From 53ad09d4268da509bf4dff2170682aa6feee1f73 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Mon, 12 Nov 2018 18:18:49 +0100 Subject: [PATCH] Fix possible dead-lock in RosPublish if a signal throws an exception. --- src/ros_publish.cpp | 6 ++++-- src/ros_publish.hh | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ros_publish.cpp b/src/ros_publish.cpp index 06d483f..c985648 100644 --- a/src/ros_publish.cpp +++ b/src/ros_publish.cpp @@ -220,9 +220,10 @@ namespace dynamicgraph } //lock the mutex to avoid deleting the signal during a call to trigger + boost::mutex::scoped_lock lock (mutex_); + signalDeregistration(signal); bindedSignal_.erase (signal); - mutex_.unlock(); } std::string RosPublish::list () const @@ -262,13 +263,14 @@ namespace dynamicgraph nextPublication_ = ros::Time::now() + rate_; + boost::mutex::scoped_lock lock (mutex_); + while(! mutex_.try_lock() ){} for (iterator_t it = bindedSignal_.begin (); it != bindedSignal_.end (); ++it) { boost::get<1>(it->second) (t); } - mutex_.unlock(); return dummy; } diff --git a/src/ros_publish.hh b/src/ros_publish.hh index 6005f3e..bd9f81b 100644 --- a/src/ros_publish.hh +++ b/src/ros_publish.hh @@ -4,7 +4,7 @@ # include <boost/shared_ptr.hpp> # include <boost/tuple/tuple.hpp> -# include <boost/interprocess/sync/interprocess_mutex.hpp> +# include <boost/thread/mutex.hpp> # include <dynamic-graph/entity.h> # include <dynamic-graph/signal-time-dependent.h> @@ -94,7 +94,7 @@ namespace dynamicgraph dynamicgraph::SignalTimeDependent<int,int> trigger_; ros::Duration rate_; ros::Time nextPublication_; - boost::interprocess::interprocess_mutex mutex_; + boost::mutex mutex_; }; } // end of namespace dynamicgraph. -- GitLab