Skip to content

Commit 53ad09d

Browse files
jmirabelOlivier Stasse
authored andcommitted
Fix possible dead-lock in RosPublish if a signal throws an exception.
1 parent 4e7542f commit 53ad09d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/ros_publish.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ namespace dynamicgraph
220220
}
221221

222222
//lock the mutex to avoid deleting the signal during a call to trigger
223+
boost::mutex::scoped_lock lock (mutex_);
224+
223225
signalDeregistration(signal);
224226
bindedSignal_.erase (signal);
225-
mutex_.unlock();
226227
}
227228

228229
std::string RosPublish::list () const
@@ -262,13 +263,14 @@ namespace dynamicgraph
262263

263264
nextPublication_ = ros::Time::now() + rate_;
264265

266+
boost::mutex::scoped_lock lock (mutex_);
267+
265268
while(! mutex_.try_lock() ){}
266269
for (iterator_t it = bindedSignal_.begin ();
267270
it != bindedSignal_.end (); ++it)
268271
{
269272
boost::get<1>(it->second) (t);
270273
}
271-
mutex_.unlock();
272274
return dummy;
273275
}
274276

src/ros_publish.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# include <boost/shared_ptr.hpp>
66
# include <boost/tuple/tuple.hpp>
7-
# include <boost/interprocess/sync/interprocess_mutex.hpp>
7+
# include <boost/thread/mutex.hpp>
88

99
# include <dynamic-graph/entity.h>
1010
# include <dynamic-graph/signal-time-dependent.h>
@@ -94,7 +94,7 @@ namespace dynamicgraph
9494
dynamicgraph::SignalTimeDependent<int,int> trigger_;
9595
ros::Duration rate_;
9696
ros::Time nextPublication_;
97-
boost::interprocess::interprocess_mutex mutex_;
97+
boost::mutex mutex_;
9898
};
9999
} // end of namespace dynamicgraph.
100100

0 commit comments

Comments
 (0)