bart | b2abfdd | 2009-03-11 19:12:06 +0000 | [diff] [blame] | 1 | // Test program that allows to verify whether Drd works fine for programs that |
| 2 | // use the boost::thread, boost::mutex and boost::condition classes. |
| 3 | |
| 4 | |
bart | 61e34a1 | 2008-11-10 18:54:46 +0000 | [diff] [blame] | 5 | #include <boost/thread/condition.hpp> |
| 6 | #include <boost/thread/mutex.hpp> |
| 7 | #include <boost/thread/thread.hpp> |
| 8 | #include <iostream> |
| 9 | |
| 10 | |
| 11 | static boost::condition s_cva; |
| 12 | static boost::mutex s_m; |
| 13 | |
| 14 | |
| 15 | static void thread_func(void) |
| 16 | { |
| 17 | std::cerr << "Thread 2.\n"; |
| 18 | boost::mutex::scoped_lock sl(s_m); |
| 19 | s_cva.notify_all(); |
| 20 | s_cva.wait(sl); |
| 21 | } |
| 22 | |
| 23 | int main(int argc, char** argv) |
| 24 | { |
| 25 | std::cerr << "Thread 1.\n"; |
| 26 | boost::mutex::scoped_lock sl(s_m); |
| 27 | boost::thread t(thread_func); |
| 28 | s_cva.wait(sl); |
| 29 | s_cva.notify_all(); |
| 30 | sl.unlock(); |
| 31 | t.join(); |
| 32 | std::cerr << "Finished.\n"; |
| 33 | return 0; |
| 34 | } |