-
Notifications
You must be signed in to change notification settings - Fork 478
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
make events threadsafe #3042
make events threadsafe #3042
Conversation
thanks for the fix. Do you have a minimal example that reproduces this segfault? |
PR looks great to me. Do we need to include the mutex lock in the destructor too? I've done it in 0096765. I've setup a branch to include changes in destructor, mutable for mutex and an experimental test that plays with 3 threads trying to force a possible race condition: a6e8999 These changes are in |
@j-rivero thanks & merged in PR |
- initial connection (insert) and cleanup (remove) locked with mutex - signal (access) checks for object not null before attempting to access (not locking because would need recursive mutex)
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
Signed-off-by: Jose Luis Rivero <jrivero@osrfoundation.org>
Umm we have a problem on Mac:
Need to look into it. |
I don't want to block this PR since it improves the current state of things. I've ticketed the issue of the test problem on Mac #3063. |
- Initial connection (insert) and cleanup (remove) locked with mutex - Signal (access) checks for object not null before attempting to access (not locking because would need recursive mutex) - Declare mutex as mutable so EventCount const method can block it - Include race condition test to play with connections inside an event (contribution by Sonia Jin from AWS, back port of #3042) Co-authored-by: Jose Luis Rivero <jrivero@osrfoundation.org>
- Initial connection (insert) and cleanup (remove) locked with mutex - Signal (access) checks for object not null before attempting to access (not locking because would need recursive mutex) - Declare mutex as mutable so EventCount const method can block it - Include race condition test to play with connections inside an event (contribution by Sonia Jin from AWS, back port of #3042) Co-authored-by: Jose Luis Rivero <jrivero@osrfoundation.org> Co-authored-by: sonia <lihui815@users.noreply.github.com>
Fixes Per issue #2874, race conditions can occur between
EventT::Connect
andEventT::Signal
. In order to address this, add lock onConnect
.However, this only keeps thread-safety between
Connect
(insert) and theCleanup
(delete) referenced fromSignal
. There is still potential race condition between the rest ofSignal
(access) andConnect
(insert). Adding a mutex lock guard here however will lock up the program as there appears to be aConnect
call from a callback, and using recursive mutexes will impact performance to some extent.Instead, since the conflict occurs between connection insertion and access, add a null check before accessing to each
Signal
definition.