本文介绍了这个程序有一些问题,帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! #include < windows.h > #include < cstdio > #include < process.h > #define MY_MSG WM_USER + 100 const int MAX_INFO_SIZE = 20 ; HANDLE hStartEvent; // 主题开始事件 / * 要把SETTING改为多线程的项目 - >设置 - > C / C ++,在类别中选代码生成,然后在使用运行时libray中选一个多线程配置 * / // 主题函数 #include < queue > 使用 命名空间标准; queue< int> g_test; unsigned __ stdcall fun( void * param) { printf( thread fun start\\\ ); hStartEvent = :: CreateEvent( 0 ,FALSE,FALSE, 0 ) ; // 创建线程启动事件 if (hStartEvent == 0 ) { printf( create start event failed,errno:%d \ n,:: GetLastError()); return 1 ; } while ( true ) { // 等待线程启动事件以避免PostThreadMessage返回错误:1444 :: WaitForSingleObject(hStartEvent) ,无穷); printf( 收到信号...,%d \ n,g_test 。面前()); g_test.pop(); } return 0 ; } int main() { HANDLE hThread; unsigned nThreadID; // start thread hThread =(HANDLE)_beginthreadex(NULL, 0 ,& fun,NULL, 0 ,& nThreadID); if (hThread == 0 ) { printf( 启动线程失败,错误号:%d \ n,:: GetLastError()); CloseHandle(hStartEvent); return 1 ; } int count = 0 ; while ( true ) { g_test.push(+ +计数); if (!SetEvent(hStartEvent)) // 设置线程启动事件 { printf( 设置启动事件失败,错误号:%d\\\,:GetLastError函数()); // 返回1; } if (count> 10) { // :: Sleep(5000); } :: Sleep( 50 ); } CloseHandle(hStartEvent); CloseHandle(hThread); return 0 ; } 解决方案 如果您没有告诉我们问题发生在什么地方,我们无法帮助您问题是。你只是给了我们一段代码,并期望我们能够/愿意努力让它在我们自己的机器上运行。 引用:这个程序有问题吗这里没有问题。你的程序正在完成代码应该做的事情。 如果你想知道它是否符合你的期望,这是另一个问题,因为你没有告诉我们你的期望是什么。 如果您知道程序出错了,请解释错误,我们可以帮助修复该程序。 #include <windows.h>#include <cstdio>#include <process.h>#define MY_MSG WM_USER+100const int MAX_INFO_SIZE = 20;HANDLE hStartEvent; // thread start event /* 要把SETTING 改为多线程的 Project->Settings->C/C++, 在Category 中选Code Generation, 然后在Use run-time libray 中选一个 Multithread 配置*/// thread function#include <queue>using namespace std;queue<int> g_test;unsigned __stdcall fun(void *param){ printf("thread fun start\n"); hStartEvent = ::CreateEvent(0,FALSE,FALSE,0); //create thread start event if(hStartEvent == 0) { printf("create start event failed,errno:%d\n",::GetLastError()); return 1; } while(true) { //wait thread start event to avoid PostThreadMessage return errno:1444 ::WaitForSingleObject(hStartEvent,INFINITE); printf("收到信号...,%d\n",g_test.front()); g_test.pop(); } return 0;}int main(){ HANDLE hThread; unsigned nThreadID; //start thread hThread = (HANDLE)_beginthreadex( NULL, 0, &fun, NULL, 0, &nThreadID ); if(hThread == 0) { printf("start thread failed,errno:%d\n",::GetLastError()); CloseHandle(hStartEvent); return 1; } int count = 0; while(true) { g_test.push(++count); if(!SetEvent(hStartEvent)) //set thread start event { printf("set start event failed,errno:%d\n",::GetLastError()); //return 1; } if (count>10) { //::Sleep(5000); } ::Sleep(50); } CloseHandle(hStartEvent); CloseHandle(hThread); return 0;} 解决方案 We can't help you if you don't tell us WHERE the problem is happening along with WHAT the problem is. You've simply given us a block of code and expect us to be able/willing to work at trying to get it to run on our own machines.Quote:Is this programe have some problemThere is no problem here. Your program is doing exactly what the code is supposed to do.If you want to know if it match your expectations, it is another problem, because you didn't told us what are your expectations.If you know that the program is doing wrong, explain what is wrong and we may be able to help fixing that program. 这篇关于这个程序有一些问题,帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 15:39