#include#include #include #include #define WIN32_LEAN_AND_MEAN DWORD WINAPI ThreadFunc(LPVOID); int main() { HANDLE hThred1; HANDLE hThred2; DWORD exitCode1 = 0; DWORD exitCode2 = 0; DWORD threadId; hThred1=CreateThread(NULL,0,ThreadFunc,(LPVOID)1,0,&threadId); if (hThred1) { printf("Thread 1 launchedn"); } hThred2 = CreateThread(NULL, 0, ThreadFunc, (LPVOID)2, 0, &threadId); if (hThred2) { printf("Thread 2 launchedn"); } for (;;) { printf("Press any key to exit..n"); _getch(); GetExitCodeThread(hThred1, &exitCode1); GetExitCodeThread(hThred2, &exitCode2); if (exitCode1 == STILL_ACTIVE) puts("Thread 1 is still running!"); if (exitCode2 == STILL_ACTIVE) puts("Thread 2 is still running!"); if (exitCode1 != STILL_ACTIVE && exitCode2 != STILL_ACTIVE) break; } CloseHandle(hThred1); CloseHandle(hThred2); printf("Thread 1 returned %dn", exitCode1); printf("Thread 2 returned %dn", exitCode2); return EXIT_SUCCESS; } DWORD WINAPI ThreadFunc(LPVOID n) { Sleep((DWORD)n * 1000 * 2); return (DWORD)n * 10; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)