13 #include <condition_variable>
24 std::atomic<int> state(0);
33 CPPUNIT_ASSERT_MESSAGE(std::string(
"state=") + std::to_string(state),
check_state(state, 1));
35 exec([&state] { state++; }, [&state] {
40 CPPUNIT_ASSERT_MESSAGE(std::string(
"state=") + std::to_string(state),
check_state(state, 3));
43 for (
int i = 0; i < 1000; i++) {
50 CPPUNIT_ASSERT_MESSAGE(std::string(
"state=") + std::to_string(state),
check_state(state, 1000));
94 std::unique_lock<std::mutex> lock(
g_mutex);
95 return g_cond.wait_for(lock, std::chrono::seconds(10), [&state, expected] {
return state == expected; });
static std::shared_ptr< dispatcher > instance()
std::condition_variable g_cond
void exec(exec_task::func_t f)
Execute code in a separate executor thread.
bool check_state(std::atomic< int > &state, int expected)