From 97ed34a042c1d4e1a88ea06986112cbdd05e08a9 Mon Sep 17 00:00:00 2001 From: Guillaume Autran Date: Mon, 22 Apr 2019 14:39:32 -0400 Subject: [PATCH] Fix a concurrency problem in the multithreaded executor (#703) 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 6c04d81..24c5c79 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(); } }