Skip to content

Commit 9e973db

Browse files
committed
Docs: fix stale and incorrect free-threading statements
* The extensions HOWTO claimed the free-threaded build does not support the stable ABI; 3.15 added abi3t. * The library FAQ described GIL-based atomicity and the GIL removal as future work without mentioning the free-threaded build. * threading no longer describes free threading as unavailable. * The free-threading HOWTO's immortalization and deferred reference counting lists were incomplete.
1 parent 7b12a41 commit 9e973db

4 files changed

Lines changed: 50 additions & 25 deletions

File tree

‎Doc/faq/library.rst‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ class provides a featureful interface.
362362
What kinds of global value mutation are thread-safe?
363363
----------------------------------------------------
364364
365-
A :term:`global interpreter lock` (GIL) is used internally to ensure that only one
366-
thread runs in the Python VM at a time. In general, Python offers to switch
365+
In the default build of CPython, a :term:`global interpreter lock` (GIL) is
366+
used internally to ensure that only one thread runs in the Python VM at a time. In general, Python offers to switch
367367
among threads only between bytecode instructions; how frequently it switches can
368368
be set via :func:`sys.setswitchinterval`. Each bytecode instruction and
369369
therefore all the C implementation code reached from each instruction is
@@ -401,6 +401,17 @@ Operations that replace other objects may invoke those other objects'
401401
affect things. This is especially true for the mass updates to dictionaries and
402402
lists. When in doubt, use a mutex!
403403
404+
.. note::
405+
406+
The above relies on the GIL. In the :term:`free-threaded <free threading>`
407+
build, where the GIL is disabled, threads can run bytecode in parallel and
408+
a bytecode instruction is not atomic in general. Built-in types such as
409+
:class:`list`, :class:`dict` and :class:`set` use internal locks so that
410+
individual operations on them still behave atomically, but compound
411+
operations such as ``D[x] = D[x] + 1`` remain unsafe. See
412+
:ref:`threadsafety` for the guarantees provided for built-in types and
413+
:ref:`freethreading-python-howto` for more information.
414+
404415
405416
Can't we get rid of the Global Interpreter Lock?
406417
------------------------------------------------
@@ -410,14 +421,14 @@ deployment on high-end multiprocessor server machines, because a multi-threaded
410421
Python program effectively only uses one CPU, due to the insistence that
411422
(almost) all Python code can only run while the GIL is held.
412423
413-
With the approval of :pep:`703` work is now underway to remove the GIL from the
414-
CPython implementation of Python. Initially it will be implemented as an
415-
optional compiler flag when building the interpreter, and so separate
416-
builds will be available with and without the GIL. Long-term, the hope is
417-
to settle on a single build, once the performance implications of removing the
418-
GIL are fully understood. Python 3.13 is likely to be the first release
419-
containing this work, although it may not be completely functional in this
420-
release.
424+
With the approval of :pep:`703` the GIL can be disabled in CPython. This is
425+
implemented as an optional compile-time flag (:option:`--disable-gil`), so
426+
separate builds are available with and without the GIL. The first release
427+
containing this work was Python 3.13, where it was experimental; the
428+
:term:`free-threaded <free threading>` build is officially supported as of
429+
Python 3.14. See :ref:`freethreading-python-howto` for details. Long-term,
430+
the hope is to settle on a single build, once the performance implications of
431+
removing the GIL are fully understood.
421432
422433
The current work to remove the GIL is based on a
423434
`fork of Python 3.9 with the GIL removed <https://github.com/colesbury/nogil>`_

‎Doc/howto/free-threading-extensions.rst‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,24 @@ The wheels, shared libraries, and binaries are indicated by a ``t`` suffix.
425425
Limited C API and Stable ABI
426426
............................
427427

428-
The free-threaded build does not currently support the
428+
Starting with Python 3.15, the free-threaded build supports the
429+
:ref:`Limited C API <limited-c-api>` and a variant of the stable ABI called
430+
``abi3t``. See :ref:`abi3t-migration-howto` for how to target it, and
431+
:ref:`stable-abi` for how ``abi3t`` relates to ``abi3``.
432+
433+
The free-threaded builds of Python 3.14 and older do not support the
429434
:ref:`Limited C API <limited-c-api>` or the stable ABI. If you use
430435
`setuptools <https://setuptools.pypa.io/en/latest/setuptools.html>`_ to build
431-
your extension and currently set ``py_limited_api=True`` you can use
436+
your extension for these versions and currently set ``py_limited_api=True``,
437+
you can use
432438
``py_limited_api=not sysconfig.get_config_var("Py_GIL_DISABLED")`` to opt out
433439
of the limited API when building with the free-threaded build.
434440

435441
.. note::
436-
You will need to build separate wheels specifically for the free-threaded
437-
build. If you currently use the stable ABI, you can continue to build a
438-
single wheel for multiple non-free-threaded Python versions.
442+
Unless you target ``abi3t``, you will need to build separate wheels
443+
specifically for the free-threaded build. If you use the ``abi3`` stable
444+
ABI, you can continue to build a single wheel for multiple
445+
non-free-threaded Python versions.
439446

440447

441448
Windows

‎Doc/howto/free-threading-python.rst‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ As of the 3.14 release, immortalization is limited to:
105105

106106
* Code constants: numeric literals, string literals, and tuple literals
107107
composed of other constants.
108-
* Strings interned by :func:`sys.intern`.
108+
* All interned strings, including those interned by :func:`sys.intern`
109+
and the names used in code objects (see
110+
:ref:`below <ft-interned-immortal>`).
111+
112+
Objects that are immortal in the default build, such as ``None``, small
113+
integers and static types, are also immortal in the free-threaded build.
109114

110115

111116
Frame objects
@@ -171,6 +176,8 @@ The free-threaded build will typically use more memory compared to the default
171176
build. There are multiple reasons for this, mostly due to design decisions.
172177

173178

179+
.. _ft-interned-immortal:
180+
174181
All interned strings are immortal
175182
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
176183

@@ -255,7 +262,8 @@ following types:
255262

256263
* module objects
257264
* module top-level functions
258-
* class methods defined in the class scope
265+
* functions defined in a class scope (methods)
266+
* :func:`classmethod` and :func:`staticmethod` objects
259267
* descriptor objects
260268
* thread-local objects, created by :class:`threading.local`
261269

‎Doc/library/threading.rst‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,15 @@ GIL and performance considerations
9797
Unlike the :mod:`multiprocessing` module, which uses separate processes to
9898
bypass the :term:`global interpreter lock` (GIL), the threading module operates
9999
within a single process, meaning that all threads share the same memory space.
100-
However, the GIL limits the performance gains of threading when it comes to
101-
CPU-bound tasks, as only one thread can execute Python bytecode at a time.
102-
Despite this, threads remain a useful tool for achieving concurrency in many
103-
scenarios.
100+
However, in the default build the GIL limits the performance gains of threading
101+
when it comes to CPU-bound tasks, as only one thread can execute Python
102+
bytecode at a time. Despite this, threads remain a useful tool for achieving
103+
concurrency in many scenarios.
104104

105105
As of Python 3.13, :term:`free-threaded <free threading>` builds
106-
can disable the GIL, enabling true parallel execution of threads, but this
107-
feature is not available by default (see :pep:`703`).
108-
109-
.. TODO: At some point this feature will become available by default.
106+
can disable the GIL, enabling true parallel execution of threads. These
107+
builds are separate from the default build and must be installed or built
108+
explicitly (see :pep:`703` and :ref:`freethreading-python-howto`).
110109

111110
Reference
112111
---------

0 commit comments

Comments
 (0)