MCPcopy Create free account
hub / github.com/bshoshany/thread-pool / check_wait

Function check_wait

tests/BS_thread_pool_test.cpp:1427–1445  ·  view source on GitHub ↗

* @brief Check that wait() works. */

Source from the content-addressed store, hash-verified

1425 * @brief Check that wait() works.
1426 */
1427void check_wait()
1428{
1429 constexpr std::chrono::milliseconds sleep_time(10);
1430 BS::thread_pool pool;
1431 const std::size_t num_tasks = pool.get_thread_count() * 10;
1432 std::vector<std::atomic<bool>> flags(num_tasks);
1433 for (std::size_t i = 0; i < num_tasks; ++i)
1434 {
1435 pool.detach_task(
1436 [&flags, i, sleep_time]
1437 {
1438 std::this_thread::sleep_for(sleep_time);
1439 flags[i] = true;
1440 });
1441 }
1442 logln("Waiting for tasks...");
1443 pool.wait();
1444 check(all_flags_set(flags));
1445}
1446
1447/**
1448 * @brief Check that wait() correctly blocks all external threads that call it.

Callers 1

mainFunction · 0.85

Calls 4

loglnFunction · 0.85
checkFunction · 0.85
all_flags_setFunction · 0.85
waitMethod · 0.80

Tested by

no test coverage detected