@@ -148,10 +148,7 @@ typedef CCheckQueue<FrozenCleanupCheck> FrozenCleanup_Queue;
148148static void Correct_Queue_range (std::vector<size_t > range)
149149{
150150 auto small_queue = MakeUnique<Correct_Queue>(QUEUE_BATCH_SIZE);
151- boost::thread_group tg;
152- for (auto x = 0 ; x < SCRIPT_CHECK_THREADS; ++x) {
153- tg.create_thread ([&]{small_queue->Thread ();});
154- }
151+ small_queue->StartWorkerThreads (SCRIPT_CHECK_THREADS);
155152 // Make vChecks here to save on malloc (this test can be slow...)
156153 std::vector<FakeCheckCheckCompletion> vChecks;
157154 for (const size_t i : range) {
@@ -168,8 +165,7 @@ static void Correct_Queue_range(std::vector<size_t> range)
168165 BOOST_REQUIRE_EQUAL (FakeCheckCheckCompletion::n_calls, i);
169166 }
170167 }
171- tg.interrupt_all ();
172- tg.join_all ();
168+ small_queue->StopWorkerThreads ();
173169}
174170
175171/* * Test that 0 checks is correct
@@ -212,11 +208,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random)
212208BOOST_AUTO_TEST_CASE (test_CheckQueue_Catches_Failure)
213209{
214210 auto fail_queue = MakeUnique<Failing_Queue>(QUEUE_BATCH_SIZE);
215-
216- boost::thread_group tg;
217- for (auto x = 0 ; x < SCRIPT_CHECK_THREADS; ++x) {
218- tg.create_thread ([&]{fail_queue->Thread ();});
219- }
211+ fail_queue->StartWorkerThreads (SCRIPT_CHECK_THREADS);
220212
221213 for (size_t i = 0 ; i < 1001 ; ++i) {
222214 CCheckQueueControl<FailingCheck> control (fail_queue.get ());
@@ -237,18 +229,14 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure)
237229 BOOST_REQUIRE (success);
238230 }
239231 }
240- tg.interrupt_all ();
241- tg.join_all ();
232+ fail_queue->StopWorkerThreads ();
242233}
243234// Test that a block validation which fails does not interfere with
244235// future blocks, ie, the bad state is cleared.
245236BOOST_AUTO_TEST_CASE (test_CheckQueue_Recovers_From_Failure)
246237{
247238 auto fail_queue = MakeUnique<Failing_Queue>(QUEUE_BATCH_SIZE);
248- boost::thread_group tg;
249- for (auto x = 0 ; x < SCRIPT_CHECK_THREADS; ++x) {
250- tg.create_thread ([&]{fail_queue->Thread ();});
251- }
239+ fail_queue->StartWorkerThreads (SCRIPT_CHECK_THREADS);
252240
253241 for (auto times = 0 ; times < 10 ; ++times) {
254242 for (const bool end_fails : {true , false }) {
@@ -263,8 +251,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
263251 BOOST_REQUIRE (r != end_fails);
264252 }
265253 }
266- tg.interrupt_all ();
267- tg.join_all ();
254+ fail_queue->StopWorkerThreads ();
268255}
269256
270257// Test that unique checks are actually all called individually, rather than
@@ -273,11 +260,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure)
273260BOOST_AUTO_TEST_CASE (test_CheckQueue_UniqueCheck)
274261{
275262 auto queue = MakeUnique<Unique_Queue>(QUEUE_BATCH_SIZE);
276- boost::thread_group tg;
277- for (auto x = 0 ; x < SCRIPT_CHECK_THREADS; ++x) {
278- tg.create_thread ([&]{queue->Thread ();});
279-
280- }
263+ queue->StartWorkerThreads (SCRIPT_CHECK_THREADS);
281264
282265 size_t COUNT = 100000 ;
283266 size_t total = COUNT;
@@ -300,8 +283,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
300283 }
301284 BOOST_REQUIRE (r);
302285 }
303- tg.interrupt_all ();
304- tg.join_all ();
286+ queue->StopWorkerThreads ();
305287}
306288
307289
@@ -313,10 +295,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck)
313295BOOST_AUTO_TEST_CASE (test_CheckQueue_Memory)
314296{
315297 auto queue = MakeUnique<Memory_Queue>(QUEUE_BATCH_SIZE);
316- boost::thread_group tg;
317- for (auto x = 0 ; x < SCRIPT_CHECK_THREADS; ++x) {
318- tg.create_thread ([&]{queue->Thread ();});
319- }
298+ queue->StartWorkerThreads (SCRIPT_CHECK_THREADS);
320299 for (size_t i = 0 ; i < 1000 ; ++i) {
321300 size_t total = i;
322301 {
@@ -335,20 +314,16 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory)
335314 }
336315 BOOST_REQUIRE_EQUAL (MemoryCheck::fake_allocated_memory, 0U );
337316 }
338- tg.interrupt_all ();
339- tg.join_all ();
317+ queue->StopWorkerThreads ();
340318}
341319
342320// Test that a new verification cannot occur until all checks
343321// have been destructed
344322BOOST_AUTO_TEST_CASE (test_CheckQueue_FrozenCleanup)
345323{
346324 auto queue = MakeUnique<FrozenCleanup_Queue>(QUEUE_BATCH_SIZE);
347- boost::thread_group tg;
348325 bool fails = false ;
349- for (auto x = 0 ; x < SCRIPT_CHECK_THREADS; ++x) {
350- tg.create_thread ([&]{queue->Thread ();});
351- }
326+ queue->StartWorkerThreads (SCRIPT_CHECK_THREADS);
352327 std::thread t0 ([&]() {
353328 CCheckQueueControl<FrozenCleanupCheck> control (queue.get ());
354329 std::vector<FrozenCleanupCheck> vChecks (1 );
@@ -378,9 +353,8 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup)
378353 FrozenCleanupCheck::cv.notify_one ();
379354 // Wait for control to finish
380355 t0.join ();
381- tg.interrupt_all ();
382- tg.join_all ();
383356 BOOST_REQUIRE (!fails);
357+ queue->StopWorkerThreads ();
384358}
385359
386360
@@ -445,4 +419,3 @@ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks)
445419 }
446420}
447421BOOST_AUTO_TEST_SUITE_END ()
448-
0 commit comments