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

Function check_wait_for

tests/BS_thread_pool_test.cpp:1491–1510  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1489 * @brief Check that wait_for() works.
1490 */
1491void check_wait_for()
1492{
1493 constexpr std::chrono::milliseconds long_sleep_time(250);
1494 constexpr std::chrono::milliseconds short_sleep_time(10);
1495 BS::thread_pool pool;
1496 logln("Checking that wait_for() works...");
1497 std::atomic<bool> done = false;
1498 pool.detach_task(
1499 [&done, long_sleep_time]
1500 {
1501 std::this_thread::sleep_for(long_sleep_time);
1502 done = true;
1503 });
1504 logln("Task that lasts ", long_sleep_time.count(), "ms submitted. Waiting for ", short_sleep_time.count(), "ms...");
1505 pool.wait_for(short_sleep_time);
1506 check(!done);
1507 logln("Waiting for ", long_sleep_time.count() * 2, "ms...");
1508 pool.wait_for(long_sleep_time * 2);
1509 check(done);
1510}
1511
1512/**
1513 * @brief Check that wait_until() works.

Callers 1

mainFunction · 0.85

Calls 3

loglnFunction · 0.85
checkFunction · 0.85
wait_forMethod · 0.80

Tested by

no test coverage detected