From e629ced66ae222e8f883326d52f83c191e64ab09 Mon Sep 17 00:00:00 2001 From: Guillaume Autran Date: Thu, 18 Apr 2019 17:03:50 -0400 Subject: [PATCH] Fix a concurrency problem in the multithreaded executor Both, the `Executor::execute_any_executable` and the destructor for the `AnyExecutable` object used by the multithreaded executor, reset the `can_be_taken_from_` flag on a MutuallyExclusive group. This cause the variable to get out of sync and threads to process executables out of sequence. This fix clears the callback group variable of the `AnyExecutable` instance effectively preventing its destructor from modifying the variable at the wrong time. Issue: #702 Signed-off-by: Guillaume Autran --- rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp b/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp index 6c04d81315..24c5c79b2c 100644 --- a/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp +++ b/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp @@ -101,5 +101,8 @@ MultiThreadedExecutor::run(size_t) scheduled_timers_.erase(it); } } + // Clear the callback_group to prevent the AnyExecutable destructor from + // resetting the callback group `can_be_taken_from` + any_exec.callback_group.reset(); } }