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
|
#include <string>
#include <iostream>
#include <windows.h>
using namespace std;
long WINAPI thread1()
{
for(int i = 0; i < 10; i++)
{
cout<<"Thread1"<<endl;
Sleep(1000);
}
return 0;
}
long WINAPI thread2()
{
for(int i = 0; i < 10; i++)
{
cout<<"Thread2"<<endl;
Sleep(200);
}
return 0;
}
int main(int argc, char **argv)
{
HANDLE hThread1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread1, 0, 0, 0);
HANDLE hThread2 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)thread2, 0, 0, 0);
WaitForSingleObject(hThread1, INFINITE);
WaitForSingleObject(hThread2, INFINITE);
CloseHandle(hThread1);
CloseHandle(hThread2);
return 0;
}
|