-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitThread.cpp
More file actions
32 lines (25 loc) · 768 Bytes
/
Copy pathWaitThread.cpp
File metadata and controls
32 lines (25 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "stdafx.h"
#include "Windows.h"
#include "iostream"
using namespace std;
DWORD WINAPI ThreadProc(PVOID pParam)
{
DWORD dwDelay = (DWORD)pParam;
cout << ">>>>> Thread " << GetCurrentThreadId() << " enter." << endl;
Sleep(5000);
cout << "<<<<< Thread " << GetCurrentThreadId() << " leave." << endl;
return dwDelay;
}
void _tmain()
{
cout << "Main thread creating sub thread..." << endl;
DWORD dwThreadID = 0;
HANDLE hThread = CreateThread(NULL, 0, ThreadProc, (PVOID)5000, 0, &dwThreadID);
// Sleep(10000);
WaitForSingleObject(hThread, INFINITE);
DWORD dwExitCode;
GetExitCodeThread(hThread, &dwExitCode);
cout << "\nSub thread " << dwThreadID << " terminated. " << endl;
cout << "Exit code=" << dwExitCode << endl;
CloseHandle(hThread);
}