Skip to content

Commit 467ec09

Browse files
committed
Some more thread safety notes
1 parent 2f74db1 commit 467ec09

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Doc/c-api/gcsupport.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,13 @@ The :c:member:`~PyTypeObject.tp_traverse` handler must have the following type:
334334
The :c:member:`~PyTypeObject.tp_traverse` function can be called from any
335335
thread.
336336
337+
.. impl-detail::
338+
339+
Garbage collection is a "stop-the-world" operation:
340+
even in :term:`free threading` builds, only one thread state is
341+
:term:`attached <attached thread state>` when :c:member:`!tp_traverse`
342+
handlers run.
343+
337344
.. versionchanged:: 3.9
338345
339346
Heap-allocated types are expected to visit ``Py_TYPE(self)`` in
@@ -372,7 +379,8 @@ The following functions and macros are safe to use in a
372379
* the *visit* function passed to ``tp_traverse``
373380
* :c:func:`Py_VISIT`
374381
* :c:func:`Py_SIZE`
375-
* :c:func:`Py_TYPE`
382+
* :c:func:`Py_TYPE`: if called from a :c:member:`!tp_traverse` handler,
383+
:c:func:`!Py_TYPE`'s result will be valid for the duration of the handler call
376384
* :c:func:`PyObject_VisitManagedDict`
377385
* :c:func:`PyObject_TypeCheck`, :c:func:`PyType_IsSubtype`,
378386
:c:func:`PyType_HasFeature`

0 commit comments

Comments
 (0)