@@ -21,32 +21,32 @@ extern "C" {
2121// interpreter at the same time. Only the "bound" thread may perform the
2222// transitions between "attached" and "detached" on its own PyThreadState.
2323//
24- // The "suspended" state is used to implement stop-the-world pauses, such as
25- // for cyclic garbage collection. It is only used in `--disable-gil` builds.
26- // The "suspended" state is similar to the "detached" state in that in both
27- // states the thread is not allowed to call most Python APIs. However, unlike
28- // the "detached" state, a thread may not transition itself out from the
29- // "suspended" state. Only the thread performing a stop-the-world pause may
30- // transition a thread from the "suspended" state back to the "detached" state.
24+ // The "suspended" states are used to implement stop-the-world pauses and to
25+ // merge biased reference counts on behalf of detached threads. They are only
26+ // used in `--disable-gil` builds.
27+ // They are similar to the "detached" state in that the thread is not allowed
28+ // to call most Python APIs. A suspended thread trying to attach marks itself
29+ // as "suspended-waiting". Only the thread responsible for suspending it may
30+ // resume it, moving it to "detached" or "detached-waiting".
31+ // A "detached-waiting" thread must attach before it can be suspended again.
3132//
3233// The "shutting down" state is used when the interpreter is being finalized.
3334// Threads in this state can't do anything other than block the OS thread.
3435// (See _PyThreadState_HangThread).
3536//
36- // State transition diagram:
37- //
38- // (bound thread) (stop-the-world thread)
39- // [attached] <-> [detached] <-> [suspended]
40- // | ^
41- // +---------------------------->---------------------------+
42- // (bound thread)
43- //
44- // The (bound thread) and (stop-the-world thread) labels indicate which thread
45- // is allowed to perform the transition.
46- #define _Py_THREAD_DETACHED 0
47- #define _Py_THREAD_ATTACHED 1
48- #define _Py_THREAD_SUSPENDED 2
49- #define _Py_THREAD_SHUTTING_DOWN 3
37+ // State transitions:
38+ // Bound thread: attached <-> detached
39+ // attached -> suspended
40+ // suspended -> suspended-waiting
41+ // detached-waiting -> attached
42+ // Suspending thread: detached <-> suspended
43+ // suspended-waiting -> detached-waiting
44+ #define _Py_THREAD_DETACHED 0
45+ #define _Py_THREAD_ATTACHED 1
46+ #define _Py_THREAD_SUSPENDED 2
47+ #define _Py_THREAD_SHUTTING_DOWN 3
48+ #define _Py_THREAD_SUSPENDED_WAITING 4
49+ #define _Py_THREAD_DETACHED_WAITING 5
5050
5151
5252/* Check if the current thread is the main thread.
@@ -162,8 +162,9 @@ extern void _PyThreadState_Suspend(PyThreadState *tstate);
162162// Returns 1 on success, 0 if the thread was not in the "detached" state.
163163extern int _PyThreadState_TrySuspendDetached (PyThreadState * tstate );
164164
165- // Undo a successful _PyThreadState_TrySuspendDetached(): switch the thread
166- // back to "detached" and wake it if it is waiting to attach.
165+ // Resume a thread suspended by _PyThreadState_TrySuspendDetached() or a
166+ // stop-the-world pause: switch it back to "detached" or "detached-waiting"
167+ // and wake it if it is waiting to attach.
167168extern void _PyThreadState_ResumeDetached (PyThreadState * tstate );
168169#endif
169170
0 commit comments