[Windows] 쓰레드(Thread) 생성 예제
사용되는 헤더
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
걍 그대로 긁어옴
'프로그래밍 > C++' 카테고리의 다른 글
[Windows] Critical Section 겹쳐 쓰지 마.. (0) | 2014.12.15 |
---|---|
[Windows] 쓰레드(Thread) 생성&종료 함수 (0) | 2014.01.17 |
[Windows] 쓰레드(Thread) 생성 함수 - CreateThread, _beginthreadex (4) | 2014.01.17 |
[Windows] 쓰레드(Thread) 생성 함수 - CreateThread (0) | 2013.12.15 |
댓글
이 글 공유하기
다른 글
-
[Windows] Critical Section 겹쳐 쓰지 마..
[Windows] Critical Section 겹쳐 쓰지 마..
2014.12.15 -
[Windows] 쓰레드(Thread) 생성&종료 함수
[Windows] 쓰레드(Thread) 생성&종료 함수
2014.01.17 -
[Windows] 쓰레드(Thread) 생성 함수 - CreateThread, _beginthreadex
[Windows] 쓰레드(Thread) 생성 함수 - CreateThread, _beginthreadex
2014.01.17 -
[Windows] 쓰레드(Thread) 생성 함수 - CreateThread
[Windows] 쓰레드(Thread) 생성 함수 - CreateThread
2013.12.15