Skip to content

Commit

Permalink
Update async_update_stop_ within the scope of the lock to avoid missi…
Browse files Browse the repository at this point in the history
…ng notify
  • Loading branch information
saikishor committed Apr 22, 2024
1 parent cbb0617 commit 0856453
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ class AsyncFunctionHandler
{
if (is_running())
{
async_update_stop_ = true;
{
std::unique_lock<std::mutex> lock(async_mtx_);
async_update_stop_ = true;
}
async_update_condition_.notify_one();
thread_.join();
}
Expand Down
2 changes: 1 addition & 1 deletion controller_interface/test/test_async_function_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ TEST_F(AsyncFunctionHandlerTest, check_triggering)
ASSERT_TRUE(async_class.get_handler().is_initialized());
ASSERT_TRUE(async_class.get_handler().is_running());
ASSERT_FALSE(async_class.get_handler().is_stopped());
async_class.get_handler().wait_for_trigger_cycle_to_finish();
std::this_thread::sleep_for(std::chrono::microseconds(1));
async_class.get_handler().stop_async_update();
ASSERT_EQ(async_class.get_counter(), 2);

Expand Down

0 comments on commit 0856453

Please sign in to comment.