Skip to content

gh-109693: Update _gil_runtime_state.last_holder to use pyatomic.h #110605

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

Merged
merged 1 commit into from
Oct 13, 2023

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Oct 10, 2023

@@ -25,7 +25,7 @@ struct _gil_runtime_state {
unsigned long interval;
/* Last PyThreadState holding / having held the GIL. This helps us
know whether anyone else was scheduled after we dropped the GIL. */
_Py_atomic_address last_holder;
PyThreadState* last_holder;
/* Whether the GIL is already taken (-1 if uninitialized). This is
atomic because it can be read without any lock taken in ceval.c. */
_Py_atomic_int locked;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vstinner @colesbury

return (_Py_atomic_load_explicit(&gil->locked, _Py_memory_order_acquire) >= 0);

_Py_atomic_store_explicit(&gil->locked, 0, _Py_memory_order_release);

IIUC, To update locked field we need to introduce _Py_atomic_load/store_int_release/acquire

Do you have better ideas?

Copy link
Member

@vstinner vstinner Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like a good idea, for another API

EDIT: Oops, I wrote PEP not API, sorry about that :-D Need more coffee.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@corona10 corona10 merged commit 2566434 into python:main Oct 13, 2023
@corona10 corona10 deleted the gh-109693-gil branch October 13, 2023 01:07
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants