Skip to content

Commit

Permalink
TrajectoryExecutionManager: fix race condition (moveit#1709)
Browse files Browse the repository at this point in the history
Fix race condition accessing execution_thread_ by adding a new mutex.
  • Loading branch information
livanov93 authored and rhaschke committed Nov 8, 2019
1 parent 61b2445 commit bbd2718
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ class TrajectoryExecutionManager

boost::mutex execution_state_mutex_;
boost::mutex continuous_execution_mutex_;
boost::mutex execution_thread_mutex_;

boost::condition_variable continuous_execution_condition_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,8 +1172,12 @@ void TrajectoryExecutionManager::stopExecution(bool auto_clear)
ROS_INFO_NAMED(name_, "Stopped trajectory execution.");

// wait for the execution thread to finish
execution_thread_->join();
execution_thread_.reset();
boost::mutex::scoped_lock lock(execution_thread_mutex_);
if (execution_thread_)
{
execution_thread_->join();
execution_thread_.reset();
}

if (auto_clear)
clear();
Expand All @@ -1184,8 +1188,12 @@ void TrajectoryExecutionManager::stopExecution(bool auto_clear)
else if (execution_thread_) // just in case we have some thread waiting to be joined from some point in the past, we
// join it now
{
execution_thread_->join();
execution_thread_.reset();
boost::mutex::scoped_lock lock(execution_thread_mutex_);
if (execution_thread_)
{
execution_thread_->join();
execution_thread_.reset();
}
}
}

Expand Down

0 comments on commit bbd2718

Please sign in to comment.