사용되는 헤더

process.h

사용되는 함수

_beginthreadex, _endthreadex, WaitForSingleObject, GetExitCodeThread, CloseHandle, TerminateThread

 

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
#include <iostream>
#include <Windows.h>
#include <process.h>
 
using namespace std;
 
unsigned int __stdcall BasicThread(void* arg) {
int xxx = (int)arg;
 
int result = 0;
 
for (int x = 0; x < 100; ++x) {
result += xxx++;
}
 
_endthreadex(result);
return 0;
}
 
unsigned int _stdcall InfinityThread(void *arg) {
 
while (true) {
Sleep(1000);
}
 
return 0;
}
 
void main()
{
unsigned int id;
HANDLE hand;
int xxx = 120;
 
hand = (HANDLE)_beginthreadex(NULL,0, BasicThread, (void *)xxx, 0, &id);
hand2 = (HANDLE)_beginthreadex(NULL,0, INfinityThread, (void *)xxx, 0, &id);
 
WaitForSingleObject(hand, INFINITE);
 
DWORD test = 0;
GetExitCodeThread(hand, &test);
CloseHandle(hand);
 
TerminateThread(hand2, 0);
 
std::cout<< test <<std::endl;
}

 

 

 

================================

 

[출처] http://krids.tistory.com/187

걍 그대로 긁어옴