* @brief Check that pausing works. */
| 2088 | * @brief Check that pausing works. |
| 2089 | */ |
| 2090 | void check_pausing() |
| 2091 | { |
| 2092 | constexpr std::chrono::milliseconds sleep_time(200); |
| 2093 | BS::pause_thread_pool pool; |
| 2094 | logln("Checking that the pool correctly reports that it is not paused after construction..."); |
| 2095 | check(!pool.is_paused()); |
| 2096 | logln("Pausing pool."); |
| 2097 | pool.pause(); |
| 2098 | logln("Checking that the pool correctly reports that it is paused..."); |
| 2099 | check(pool.is_paused()); |
| 2100 | logln("Submitting task and waiting."); |
| 2101 | std::atomic<bool> flag = false; |
| 2102 | pool.detach_task( |
| 2103 | [&flag] |
| 2104 | { |
| 2105 | flag = true; |
| 2106 | logln("Task executed."); |
| 2107 | }); |
| 2108 | std::this_thread::sleep_for(sleep_time); |
| 2109 | logln("Verifying that the task has not been executed..."); |
| 2110 | check(!flag); |
| 2111 | logln("Unpausing pool and waiting."); |
| 2112 | pool.unpause(); |
| 2113 | std::this_thread::sleep_for(sleep_time); |
| 2114 | logln("Verifying that the task has been executed..."); |
| 2115 | check(flag); |
| 2116 | logln("Checking that the pool correctly reports that it is not paused..."); |
| 2117 | check(!pool.is_paused()); |
| 2118 | } |
| 2119 | |
| 2120 | /** |
| 2121 | * @brief Check that purge() works. |