Ticket #1835: thread_equality.cpp

File thread_equality.cpp, 766 bytes (added by strk@…, 15 years ago)

Testcase for boost::thread equality operator

Line 
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//
10using namespace std;
11
12static boost::thread* myThread = 0;
13static boost::barrier* bar = 0;
14
15void 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
25int
26main()
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}