-
Notifications
You must be signed in to change notification settings - Fork 0
/
pid0.cpp
86 lines (68 loc) · 1.48 KB
/
pid0.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// #include<iostream>
// #include<stdlib.h>
// #include<pthread.h>
// #include<unistd.h>
// #include<boost/thread.hpp>
// using namespace std;
// pthread_mutex_t SA;
// int turn = 1;
// int i = 0;
// void ThreadProc1(){
// while(i++ < 100)
// {
// while(turn != 0);
// // pthread_mutex_lock(&SA);
// // turn = 1;
// // cout << turn << endl;
// cout << "thread 1 :" << turn << endl;
// // pthread_mutex_unlock(&SA);
// }
// }
// void ThreadProc2(){
// while(i++ < 100)
// {
// // while(turn != 1);
// // pthread_mutex_lock(&SA);
// // turn = 0;
// // cout << "thread 2 :" ;
// // pthread_mutex_unlock(&SA);
// }
// }
// int main(){
// pid_t fpid;
// pthread_mutex_init(&SA, NULL);
// boost::thread t1(ThreadProc1);
// //::thread t2(ThreadProc2);
// t1.join();
// return 0;
// }
#include<iostream>
#include<boost/thread.hpp>
using namespace std;
void threadFunc(){
cout<<"hello boost threads!"<<endl;
}
void wait(int seconds)
{
boost::this_thread::sleep(boost::posix_time::seconds(seconds));
}
void thread()
{
for (int i = 0; i < 5; ++i)
{
wait(1);
std::cout << i << std::endl;
}
}
struct ThreadFunc2{
void operator()(const int & id){
cout<<"thread #"<<id<<"hello boost Threads from operator!";
}
};
int main(){
boost::thread t(threadFunc);
t.join();
boost::thread t2(ThreadFunc2(),2);
t2.join();
return 1;
}