-
-
Notifications
You must be signed in to change notification settings - Fork 26
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
sig_block() does not nest properly #55
Comments
Would it make sense if sig_block/unblock just incremented/decremented |
Right, that general idea should work. It's just that we have to think about potential race conditions here (incrementing a variable is not an atomic operation, while setting it to a fixed number is atomic). |
True--though that raises the question as to what is cysignals' story with respect to thread-safety in the first place? sig_on/off are definitely not safe as is either. |
cysignals is not thread-safe at all (that's a different topic: #21). I'm talking about race conditions given signals (which should be handled correctly by a package which is meant to deal with signals). |
Ah I see what you're saying--just in general if a signal interrupted the increment/decrement. |
Well, GCC provides these: https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html |
Thinking about it... just incrementing/decrementing looks safe, but the reasoning why it's safe is non-trivial and needs to be documented. |
C++11 has atomic operations that are portable, and not just some gcc implementation details:
C11 has similar operations in <stdatomic.h>, just uglier syntax. Setting variables may or may not be atomic depending on the CPU. Eg on armeabi-v7a (basically all smartphones) you need a special ASM instruction to atomically set a 64-bit int which the compiler does not necessarily emit for a C/C++ assignment. |
I was thinking that as well--as long as no actual signal handlers touch the sig_block value it doesn't matter if the increment is interrupted by a signal. There's still a race condition, technically, but one that would exist either way. |
This doesn't work as expected:
This causes warnings in Sage when cysignals is compiled in debug mode.
@embray
The text was updated successfully, but these errors were encountered: