-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-109693: Use pyatomic.h for signal module #110480
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
Conversation
corona10
commented
Oct 6, 2023
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Clean-up pyatomic headers #109693
!buildbot nogil |
The regex 'nogil' did not match any buildbot builder. Is the requested builder in the list of stable builders? |
@corona10, unfortunately you can't currently request the "nogil" buildbots on a PR because they're marked as unstable and the "!buildbot" command only works for stable buildbots. I think Itamar is working on getting a nogil GitHub actions or similar to run on PRs. |
Okay got it! |
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.
LGTM
In Python 2.7, signamodule.c used: static struct {
int tripped;
PyObject *func;
} Handlers[NSIG];
static sig_atomic_t wakeup_fd = -1;
/* Speed up sigcheck() when none tripped */
static volatile sig_atomic_t is_tripped = 0; Handlers[NSIG].tripped was not atomic. The latest major change was commit 57e836c of issue gh-74991 in 2017 to use atomic types:
and:
|
This reverts commit 3696f01.
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 expected trip_signal() and _PyErr_CheckSignalsTstate() to be the same about memory order, but trip_signal() is stricter (seq cst) when it sets "tripped" member, whereas _PyErr_CheckSignalsTstate() uses "relaxed" to get "tripped". Would you mind to explain a comment to explain why "seq cst" is needed to access "tripped" and "is_tripped"?
cpython/Modules/signalmodule.c Lines 1810 to 1815 in 7e30821
Relaxed order always has a possibility of changes for the efficiency of the CPU pipeline by the compiler if the compiler thinks that it has no dependency between multiple atomic operations, so it only guarantees the single atomic operation itself. |
@@ -64,7 +60,7 @@ struct _signals_runtime_state { | |||
} wakeup; | |||
|
|||
/* Speed up sigcheck() when none tripped */ | |||
_Py_atomic_int is_tripped; | |||
int is_tripped; |
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.
Since the _Py_atomic
types are not used anymore, can you add comments mentioning that these fields must be accessed using atomic ops?
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.
Done!
Co-authored-by: Antoine Pitrou <[email protected]>
Thanks @corona10 for additional comments :-) |