1 | #include <boost/thread/thread.hpp>
|
---|
2 | #include <boost/bind.hpp>
|
---|
3 | #include <boost/thread/mutex.hpp>
|
---|
4 | #include <boost/thread/barrier.hpp>
|
---|
5 | #include <iostream>
|
---|
6 | #include <unistd.h>
|
---|
7 |
|
---|
8 | // g++ -o thread_equality -lboost_thread thread_equality.cpp
|
---|
9 | //
|
---|
10 | using namespace std;
|
---|
11 |
|
---|
12 | static boost::thread* myThread = 0;
|
---|
13 | static boost::barrier* bar = 0;
|
---|
14 |
|
---|
15 | void func()
|
---|
16 | {
|
---|
17 | cout << "Barrier waiting in func" << endl;
|
---|
18 | bar->wait();
|
---|
19 | cout << "Barrier waiting in func done" << endl;
|
---|
20 | assert(myThread);
|
---|
21 | boost::thread selfThread;
|
---|
22 | assert(*myThread == selfThread);
|
---|
23 | }
|
---|
24 |
|
---|
25 | int
|
---|
26 | main()
|
---|
27 | {
|
---|
28 | bar = new boost::barrier(2);
|
---|
29 |
|
---|
30 | myThread = new boost::thread(&func);
|
---|
31 |
|
---|
32 | cout << "Barrier waiting in main" << endl;
|
---|
33 | bar->wait();
|
---|
34 | cout << "Barrier waiting in main done" << endl;
|
---|
35 |
|
---|
36 | myThread->join();
|
---|
37 |
|
---|
38 | return EXIT_SUCCESS;
|
---|
39 | }
|
---|