-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Add new states ATTACHED
, DETACHED
, GC
to PyThreadState
to support PEP 703
#109549
Comments
ATTACHED
, DETACHED,
GC to
PyThreadState` to support PEP 703ATTACHED
, DETACHED
, GC
to PyThreadState
to support PEP 703
Yeah, having a separate field is fine. Ideally this would be part of Presumably "with GIL" builds won't need the field to be atomic. Is that right? |
That's right |
This adds a new field 'state' to PyThreadState that can take on one of three values: _Py_THREAD_ATTACHED, _Py_THREAD_DETACHED, and _Py_THREAD_GC. The "attached" and "detached" states correspond closely to closely to acquiring and releasing the GIL. The "gc" state is current unused, but will be used to implement stop-the-world GC for `--disable-gil` builds in the near future.
) This adds a new field 'state' to PyThreadState that can take on one of three values: _Py_THREAD_ATTACHED, _Py_THREAD_DETACHED, or _Py_THREAD_GC. The "attached" and "detached" states correspond closely to acquiring and releasing the GIL. The "gc" state is current unused, but will be used to implement stop-the-world GC for --disable-gil builds in the near future.
…ythongh-109915) This adds a new field 'state' to PyThreadState that can take on one of three values: _Py_THREAD_ATTACHED, _Py_THREAD_DETACHED, or _Py_THREAD_GC. The "attached" and "detached" states correspond closely to acquiring and releasing the GIL. The "gc" state is current unused, but will be used to implement stop-the-world GC for --disable-gil builds in the near future.
Feature or enhancement
To support pausing threads for garbage collection, PEP 703 requires identifying which threads may be accessing Python object internals (like reference counts). Currently, this is effectively controlled by acquiring the GIL. The PEP proposes three thread-states (https://peps.python.org/pep-0703/#thread-states):
ATTACHED
DETACHED
GC
I propose adding these states and a new field to
PyThreadState
. Like all the other fields inPyThreadState
(other thaninterp
), the field is intended to be private.Unfortunately, we can't add this to the
_status
bitfield because operations need to be atomic, and atomic operations don't work well with C bitfields.Default build (with GIL)
The attached and detached states will correspond precisely with acquiring and releasing the GIL. A thread will set it's state to
_Py_THREAD_ATTACHED
immediately after acquiring the GIL lock and set it to_Py_THREAD_DETACHED
immediately before releasing the GIL lock.The
_Py_THREAD_GC
state will not be used in the default build.--disable-gil
buildFrom https://peps.python.org/pep-0703/#thread-states:
cc @ericsnowcurrently
Linked PRs
The text was updated successfully, but these errors were encountered: