-
Notifications
You must be signed in to change notification settings - Fork 39
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
Use self-pipe trick to implement signal handlers #618
Conversation
This allows the rest of the Gazebo codebase to use callbacks that can use non async-signal-safe functions Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
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.
I think the idea of using a self-pipe here is looks good. I wonder if the implementation is cross platform (windows..)? If not, it maybe possible to implement reading the pipe with a condition variable.
I tested gz-sim and sending Ctrl+C at different times. I think it may have resolved the issue I ran into before here: gazebosim/gz-sim#2501 (review) as I haven't been able to reproduce it with this branch.
The advantage of a self-pipe is that it should be able to handle multiple signals fired in quick succession right? Maybe we could expand the test to cover the case when multiple signals are fired at the same time and verify the pipe still works fine.
Signed-off-by: Addisu Z. Taddese <[email protected]>
No, the main advantage is that our callbacks can freely use any function they want including printing to the console. Previously, since the callbacks were called in a signal handler, they were limited to using async-signal-safe functions. However, most of our callbacks did not comply with this and so risked causing a deadlock when a signal was fired. For example, I could add a test that allocates memory inside a callback, but I don't think the test would fail if we had a regression. For example, if we went back to the previous implementation, the test would still pass most of the time. So I'm not sure if it's worth the effort.
I've added (hopefully) windows support in 258a565. I doubt we can use condition variables since none of the |
Signed-off-by: Addisu Z. Taddese <[email protected]>
oh ok I was thinking of just a simple test to check if the handler is re-entrant. If it's not worth the effort then we can leave it. The new updates look good to me. |
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
🦟 Bug fix
Fixes #530
Summary
This uses the self-pipe trick to implement our signal handling so that downstream users can use any function in a callback registerd to
gz::common::SignalHandler
.TODO
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.