7
7
#include < util/time.h>
8
8
9
9
#include < boost/test/unit_test.hpp>
10
- #include < boost/thread/thread.hpp>
11
10
12
11
#include < functional>
13
12
#include < mutex>
13
+ #include < thread>
14
+ #include < vector>
14
15
15
16
BOOST_AUTO_TEST_SUITE (scheduler_tests)
16
17
@@ -69,16 +70,16 @@ BOOST_AUTO_TEST_CASE(manythreads)
69
70
BOOST_CHECK (last > now);
70
71
71
72
// As soon as these are created they will start running and servicing the queue
72
- boost::thread_group microThreads;
73
+ std::vector<std::thread> microThreads;
73
74
for (int i = 0 ; i < 5 ; i++)
74
- microThreads.create_thread (std::bind (&CScheduler::serviceQueue, µTasks));
75
+ microThreads.emplace_back (std::bind (&CScheduler::serviceQueue, µTasks));
75
76
76
77
UninterruptibleSleep (std::chrono::microseconds{600 });
77
78
now = std::chrono::system_clock::now ();
78
79
79
80
// More threads and more tasks:
80
81
for (int i = 0 ; i < 5 ; i++)
81
- microThreads.create_thread (std::bind (&CScheduler::serviceQueue, µTasks));
82
+ microThreads.emplace_back (std::bind (&CScheduler::serviceQueue, µTasks));
82
83
for (int i = 0 ; i < 100 ; i++) {
83
84
std::chrono::system_clock::time_point t = now + std::chrono::microseconds (randomMsec (rng));
84
85
std::chrono::system_clock::time_point tReschedule = now + std::chrono::microseconds (500 + randomMsec (rng));
@@ -91,7 +92,10 @@ BOOST_AUTO_TEST_CASE(manythreads)
91
92
92
93
// Drain the task queue then exit threads
93
94
microTasks.StopWhenDrained ();
94
- microThreads.join_all (); // ... wait until all the threads are done
95
+ // wait until all the threads are done
96
+ for (auto & thread: microThreads) {
97
+ if (thread.joinable ()) thread.join ();
98
+ }
95
99
96
100
int counterSum = 0 ;
97
101
for (int i = 0 ; i < 10 ; i++) {
@@ -131,9 +135,9 @@ BOOST_AUTO_TEST_CASE(singlethreadedscheduler_ordered)
131
135
// if the queues only permit execution of one task at once then
132
136
// the extra threads should effectively be doing nothing
133
137
// if they don't we'll get out of order behaviour
134
- boost::thread_group threads;
138
+ std::vector<std::thread> threads;
135
139
for (int i = 0 ; i < 5 ; ++i) {
136
- threads.create_thread (std::bind (&CScheduler::serviceQueue, &scheduler));
140
+ threads.emplace_back (std::bind (&CScheduler::serviceQueue, &scheduler));
137
141
}
138
142
139
143
// these are not atomic, if SinglethreadedSchedulerClient prevents
@@ -157,7 +161,9 @@ BOOST_AUTO_TEST_CASE(singlethreadedscheduler_ordered)
157
161
158
162
// finish up
159
163
scheduler.StopWhenDrained ();
160
- threads.join_all ();
164
+ for (auto & thread: threads) {
165
+ if (thread.joinable ()) thread.join ();
166
+ }
161
167
162
168
BOOST_CHECK_EQUAL (counter1, 100 );
163
169
BOOST_CHECK_EQUAL (counter2, 100 );
0 commit comments