-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaitForSingleObject.cpp
58 lines (44 loc) · 1.44 KB
/
WaitForSingleObject.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* \file WaitForSingleObject.cpp
* \brief
*
* \review
*/
//-------------------------------------------------------------------------------------------------
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
#include <windows.h>
//-------------------------------------------------------------------------------------------------
HANDLE hEvent {};
//-------------------------------------------------------------------------------------------------
DWORD WINAPI
SampleThread(LPVOID iValue)
{
const int iFinish = 10000;
for (int i = 0; i <= iFinish; ++ i) {
std::cout << i << std::endl;
}
::SetEvent(::hEvent);
return 0;
}
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
DWORD dwGenericThread {};
HANDLE hThread = ::CreateThread(nullptr, 0, SampleThread, nullptr, 0, &dwGenericThread);
if (hThread == nullptr) {
DWORD dwError = ::GetLastError();
std::cout << "SCM:Error in Creating thread: " << dwError << std::endl;
return EXIT_SUCCESS;
}
::hEvent = CreateEvent(nullptr, FALSE, FALSE, "Test");
std::cout << "Started waiting for the thread to complete.." << std::endl;
::WaitForSingleObject(::hEvent, INFINITE);
std::cout << "Thread Completed." << std::endl;
::CloseHandle(::hEvent);
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
#endif