Repository navigation
Conversation
Otherwise if something triggers while we're detaching, it will deadlock waiting for the condition mutex
There was a problem hiding this comment.
I haven't seen an explanation for why the mutex was being unlocked while calling
detachCondition.
When rmw_wait tries to call detachCondition it must not hold the lock on conditionMutex because another thread might have just triggered a listener which therefore holds a lock on its internalMutex_ and waits for a lock on the conditionMutex (hence deadlock since the detachCondition() functions needs to obtain a lock on the internalMutex_ - this is a classic lock inversion).
| // We're done with the condition variable now, but there's still a chance that something it was | ||
| // attached to will trigger and deadlock trying to lock the condition mutex. | ||
| // To avoid that we release it explicitly ASAP. | ||
| conditionVariable = NULL; |
There was a problem hiding this comment.
Changing the local variable should have any effect. The condition variable is still attached to all the listeners. And locally it is not being used after this line.
|
yep, that matches the situation as I observed/understand. thank you for the explanation still, but I suppose my point was actually "I haven't seen an explanation for why the mutex was only being unlocked while calling |
|
The current code which unlock the condition before the call of The main question is when does |
Re-stating to check my understanding: we don't want the listener's data to change between the time we finish waiting and the time we're checking it with We must want to make sure that only the listener that notified the condition variable gets set to 0, is that right? If so, that's the part I didn't realise. I thought that it was OK to not have the How about this: we keep the |
That sounds good to me and it doesn't leave any short term gaps where the mutex is unlocked and re-locked. 👍 |
|
Likely superseded by #147. |
|
update for posterity:
I was initially correct that there's no issue with listeners updating their data after the wait() call, and there's no need to protect those calls with the condition mutex. #147 includes this change in addition to changes to listeners to make the hasData calls threadsafe |
Otherwise if something triggers while we're detaching, it will deadlock waiting for the condition mutex
In particular, for the local_parameter tests in test_rclcpp, triggering of the graph guard condition can happen while detaching conditions.
I haven't seen an explanation for why the mutex was being unlocked while calling
detachCondition. it was added in 4da558f#diff-8225b098f1ec4debcdcee03d65ae95d5R1579 but from what I can see the condition mutex is not used by anydetachCondition. Perhaps that was just a way to prevent it from happening most of the time.