@@ -963,8 +963,8 @@ a file, so that other Python threads can run in the meantime.
963963
964964The Python interpreter keeps some thread-specific bookkeeping information 
965965inside a data structure called :c:type:`PyThreadState`, known as a :term:`thread state`. 
966- There's also one :term:` thread-local variable <current thread state>` pointing to the 
967- current :c:type:`PyThreadState`: it can be retrieved using :c:func:`PyThreadState_Get `.
966+ Each OS thread has a  thread-local pointer to a :c:type:`PyThreadState`; a thread state 
967+ referenced by this pointer is considered to be :term:`attached <attached thread state> `.
968968
969969A thread can only have one :term:`attached thread state` at a time. An attached 
970970thread state is typically analogous with holding the :term:`GIL`, except on 
@@ -1204,14 +1204,13 @@ code, or when embedding the Python interpreter:
12041204
12051205.. c:function:: PyThreadState* PyEval_SaveThread() 
12061206
1207-    Detach the :term:`thread state <attached thread state>` and 
1208-    return it. The :term:`current thread state` will be ``NULL`` upon 
1209-    returning. 
1207+    Detach the :term:`attached thread state` and return it. 
1208+    The thread will have no :term:`thread state` upon returning. 
12101209
12111210
12121211.. c:function:: void PyEval_RestoreThread(PyThreadState *tstate) 
12131212
1214-    Set the :term:`current  thread state` to *tstate*, which must not be ``NULL`` . 
1213+    Set the :term:`attached  thread state` to *tstate*. 
12151214   The passed :term:`thread state` **should not** be :term:`attached <attached thread state>`, 
12161215   otherwise deadlock ensues. *tstate* will be attached upon returning. 
12171216
@@ -1227,13 +1226,13 @@ code, or when embedding the Python interpreter:
12271226
12281227.. c:function:: PyThreadState* PyThreadState_Get() 
12291228
1230-    Return the :term:`current thread state`. If the :term:`current thread state` is ``NULL`` 
1231-    (such as when inside of :c:macro:`Py_BEGIN_ALLOW_THREADS` block), then this issues a fatal 
1232-    error (so that the caller needn't check for ``NULL``). 
1229+    Return the :term:`attached thread state`. If the thread has no attached 
1230+    thread state, (such as when inside of :c:macro:`Py_BEGIN_ALLOW_THREADS` 
1231+    block), then this issues a fatal error (so that the caller needn't check 
1232+    for ``NULL``). 
12331233
12341234   See also :c:func:`PyThreadState_GetUnchecked`. 
12351235
1236- 
12371236.. c:function:: PyThreadState* PyThreadState_GetUnchecked() 
12381237
12391238   Similar to :c:func:`PyThreadState_Get`, but don't kill the process with a 
@@ -1247,14 +1246,11 @@ code, or when embedding the Python interpreter:
12471246
12481247.. c:function:: PyThreadState* PyThreadState_Swap(PyThreadState *tstate) 
12491248
1250-    Set the :term:`current  thread state` to *tstate* (which may be ``NULL``) , and return 
1251-    the old value . 
1249+    Set the :term:`attached  thread state` to *tstate*, and return the  
1250+    :term:`thread state` that was attached prior to calling . 
12521251
1253-    If there is an :term:`attached thread state` for the current 
1254-    thread, it will be detached. Upon returning from this function, 
1255-    *tstate* will become :term:`attached <attached thread state>` instead 
1256-    (if it's not ``NULL``). If it is ``NULL``, then the :term:`current thread state` 
1257-    will be ``NULL``. 
1252+    This function is safe to call without an :term:`attached thread state`; it 
1253+    will simply return ``NULL`` indicating that there was no prior thread state. 
12581254
12591255
12601256The following functions use thread-local storage, and are not compatible 
@@ -1263,7 +1259,7 @@ with sub-interpreters:
12631259.. c:function:: PyGILState_STATE PyGILState_Ensure() 
12641260
12651261   Ensure that the current thread is ready to call the Python C API regardless 
1266-    of the current state of Python, or of the :term:`current  thread state`. This may 
1262+    of the current state of Python, or of the :term:`attached  thread state`. This may 
12671263   be called as many times as desired by a thread as long as each call is 
12681264   matched with a call to :c:func:`PyGILState_Release`. In general, other 
12691265   thread-related APIs may be used between :c:func:`PyGILState_Ensure` and 
@@ -1305,11 +1301,13 @@ with sub-interpreters:
13051301
13061302.. c:function:: PyThreadState* PyGILState_GetThisThreadState() 
13071303
1308-    Get the :term:`current  thread state` for this thread.  May return ``NULL`` if no 
1304+    Get the :term:`attached  thread state` for this thread.  May return ``NULL`` if no 
13091305   GILState API has been used on the current thread.  Note that the main thread 
13101306   always has such a thread-state, even if no auto-thread-state call has been 
13111307   made on the main thread.  This is mainly a helper/diagnostic function. 
13121308
1309+    .. seealso: PyThreadState_Get 
1310+ 
13131311
13141312.. c:function:: int PyGILState_Check() 
13151313
@@ -1420,10 +1418,11 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
14201418
14211419.. c:function:: void PyThreadState_DeleteCurrent(void) 
14221420
1423-    Destroy the :term:`attached thread state` and set the :term:`current thread state` 
1424-    to ``NULL``. The :term:`thread state <attached thread state>` must have been reset 
1425-    with a previous call to :c:func:`PyThreadState_Clear`. 
1421+    Detach the :term:`attached thread state` (which must have been reset 
1422+    with a previous call to :c:func:`PyThreadState_Clear`) and then destroy it. 
14261423
1424+    No :term:`thread state` will be :term:`attached <attached thread state>` upon 
1425+    returning. 
14271426
14281427.. c:function:: PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate) 
14291428
@@ -1564,8 +1563,10 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
15641563
15651564.. c:function:: void PyEval_AcquireThread(PyThreadState *tstate) 
15661565
1567-    Set the :term:`current thread state` to *tstate*, which must not be ``NULL`` or 
1568-    :term:`attached <attached thread state>`. 
1566+    :term:`Attach <attached thread state>` *tstate* to the current thread, 
1567+    which must not be ``NULL`` or already :term:`attached <attached thread state>`. 
1568+ 
1569+    The calling thread must not already have an :term:`attached thread state`. 
15691570
15701571   .. note:: 
15711572      Calling this function from a thread when the runtime is finalizing will 
@@ -1588,7 +1589,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
15881589
15891590.. c:function:: void PyEval_ReleaseThread(PyThreadState *tstate) 
15901591
1591-    Reset  the :term:`current  thread state` to ``NULL` `. 
1592+    Detach  the :term:`attached  thread state`. 
15921593   The *tstate* argument, which must not be ``NULL``, is only used to check 
15931594   that it represents the :term:`attached thread state` --- if it isn't, a fatal error is 
15941595   reported. 
@@ -1830,7 +1831,7 @@ function. You can create and destroy them using the following functions:
18301831
18311832   Destroy the (sub-)interpreter represented by the given :term:`thread state`. 
18321833   The given thread state must be :term:`attached <attached thread state>`. 
1833-    When the call returns, the  :term:`current  thread state` is ``NULL` `. 
1834+    When the call returns, there will be no  :term:`attached  thread state`. 
18341835   All thread states associated with this interpreter are destroyed. 
18351836
18361837   :c:func:`Py_FinalizeEx` will destroy all sub-interpreters that 
@@ -1933,12 +1934,9 @@ pointer and a void pointer argument.
19331934   notification recursively, but it can still be interrupted to switch 
19341935   threads if the :term:`thread state <attached thread state>` is detached. 
19351936
1936-    This function doesn't need a current thread state to run, and it doesn't 
1937-    need an :term:`attached thread state`. 
1938- 
1939-    To call this function in a subinterpreter, the caller must have an 
1940-    :term:`attached thread state`. Otherwise, the function *func* can be scheduled to 
1941-    be called from the wrong interpreter. 
1937+    This function doesn't need an :term:`attached thread state`. However, to call this 
1938+    function in a subinterpreter, the caller must have an :term:`attached thread state`. 
1939+    Otherwise, the function *func* can be scheduled to be called from the wrong interpreter. 
19421940
19431941   .. warning:: 
19441942      This is a low-level function, only useful for very special cases. 
0 commit comments