* @brief Check that wait_for() works. */
| 1489 | * @brief Check that wait_for() works. |
| 1490 | */ |
| 1491 | void 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. |