#include "windows.h" #include "stdio.h" #include "winbase.h" HANDLE hEvent=NULL; DWORD WINAPI TestFun(LPVOID lpParam) { ::WaitForSingleObject(hEvent,INFINITE); char sz[4]; ::sprintf(sz,"%d",lpParam); ::MessageBoxA(NULL,sz,NULL,MB_OK); return 0; } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { int nCount=0; hEvent=::CreateEventA(NULL,FALSE,FALSE,"EvTest"); CreateThread(NULL,0,TestFun,(LPVOID)++nCount,0,NULL); CreateThread(NULL,0,TestFun,(LPVOID)++nCount,0,NULL); CreateThread(NULL,0,TestFun,(LPVOID)++nCount,0,NULL); CreateThread(NULL,0,TestFun,(LPVOID)++nCount,0,NULL); ::MessageBoxA(NULL,"一次",NULL,MB_OK); ::SetEvent(hEvent); ::MessageBoxA(NULL,"一次",NULL,MB_OK); ::SetEvent(hEvent); ::MessageBoxA(NULL,"两次",NULL,MB_OK); ::SetEvent(hEvent); ::SetEvent(hEvent); ::MessageBoxA(NULL,"打住,再点就看不到效果了",NULL,MB_OK); return 0; }
顺序好像是乱的