* @brief Check that wait_until() works. */
| 1513 | * @brief Check that wait_until() works. |
| 1514 | */ |
| 1515 | void check_wait_until() |
| 1516 | { |
| 1517 | constexpr std::chrono::milliseconds long_sleep_time(250); |
| 1518 | constexpr std::chrono::milliseconds short_sleep_time(10); |
| 1519 | BS::thread_pool pool; |
| 1520 | logln("Checking that wait_until() works..."); |
| 1521 | std::atomic<bool> done = false; |
| 1522 | pool.detach_task( |
| 1523 | [&done, long_sleep_time] |
| 1524 | { |
| 1525 | std::this_thread::sleep_for(long_sleep_time); |
| 1526 | done = true; |
| 1527 | }); |
| 1528 | const std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); |
| 1529 | logln("Task that lasts ", long_sleep_time.count(), "ms submitted. Waiting until ", short_sleep_time.count(), "ms from submission time..."); |
| 1530 | pool.wait_until(now + short_sleep_time); |
| 1531 | check(!done); |
| 1532 | logln("Waiting until ", long_sleep_time.count() * 2, "ms from submission time..."); |
| 1533 | pool.wait_until(now + long_sleep_time * 2); |
| 1534 | check(done); |
| 1535 | } |
| 1536 | |
| 1537 | // An auxiliary thread pool used by check_wait_multiple_deadlock(). It's a global variable so that the program will not get stuck upon destruction of this pool if a deadlock actually occurs. |
| 1538 | BS::thread_pool check_wait_multiple_deadlock_pool; |
no test coverage detected