Ticket #11562: ThreadsTest.cpp

File ThreadsTest.cpp, 1.1 KB (added by boriss@…, 7 years ago)
Line 
1#include "stdafx.h"
2
3class ThreadsTest
4{
5public:
6 void testThreads()
7 {
8 while (!mIsInterrupted)
9 {
10 {
11 boost::recursive_mutex::scoped_lock _lock1(m_CsQueuedItems);
12 boost::chrono::time_point<boost::chrono::steady_clock> untilTime(boost::chrono::steady_clock::now() + boost::chrono::milliseconds(500));
13 m_EvQueuedItems.wait_until(_lock1, untilTime);
14 }
15 }
16 }
17
18 void runThread()
19 {
20 mIsInterrupted=false;
21 {
22 boost::recursive_mutex::scoped_lock _lock1(m_CsQueuedItems);
23 boost::thread newThread(boost::bind(&ThreadsTest::runThread, this));
24 }
25 boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
26 mIsInterrupted=true;
27 boost::this_thread::sleep_for(boost::chrono::milliseconds(1000));
28 }
29private:
30 boost::recursive_mutex m_CsQueuedItems;
31 boost::condition_variable_any m_EvQueuedItems;
32 bool mIsInterrupted;
33};
34
35
36int main(int argc, char* argv[])
37{
38 cout << "Starting test" << endl;
39 ThreadsTest test;
40 test.testThreads();
41 cout << "Ending test" << endl;
42 return 0;
43}
44