-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed the possibility of deadlock in detachAll method in wholebodydynamics and baseEstimatorV1 #146
Conversation
…amics and baseEstimatorV1
Interstingly, when using |
Indeed sometimes we had to kill the |
Interesting! Let's see if this PR fixes that behaviour. |
we almost always run the yarprobotinterface through tagging @HosameldinMohamed to confirm. (EDIT: which is already reviewer of the PR so I think he received the notification already :-)) |
If I am not wrong, the |
According to @Nicogene he is not experiencing any deadlock even without this PR. So probably there was some particular bug fixed in robotology/gazebo-yarp-plugins#618 that highlighted this deadlock. In any case, I think it is something worth fixing. |
I don't think I faced this issue with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you said, it's a good fix nonetheless.
Thanks!
Thanks! |
While debugging robotology/gazebo-yarp-plugins#619 (comment), I noticed that the
gazebo_yarp_robotinterface
while closing was hanging during this phase:It turns out that indeed there is the possibility of a deadlock. The case is when
detachAll
is called bythread2
and is able to lock thethis->deviceMutex
whenyarp::os::PeriodicThread
(thread1) already started its loop (i.e.step
was called) but therun
method was not called, i.e. if the execution of thread1 is on a line that goes from https://github.com/robotology/yarp/blob/v3.6.0/src/libYARP_os/src/yarp/os/PeriodicThread.cpp#L226 to https://github.com/robotology/yarp/blob/v3.6.0/src/libYARP_os/src/yarp/os/PeriodicThread.cpp#L246 .In that case,
thread2
is blocked in PeriodicThread::stop (while lockingthis->deviceMutex
) as that call contains a call tojoin
ofthread1
, butthread1
was blocked at the beginning of therun
method (https://github.com/robotology/whole-body-estimators/blob/v0.6.1/devices/wholeBodyDynamics/WholeBodyDynamicsDevice.cpp#L2704) waiting forthis->deviceMutex
to be available, a classical example of deadlock.A simple way to get rid of the deadlock is just call the stop of a thread before the
this->deviceMutex
is locked.