@@ -265,25 +265,31 @@ also be modified.
265265Free threading
266266--------------
267267
268- Mypyc has basic support for free threading, but it doesn't provide the
269- same memory safety guarantees as Python in compiled modules, since
270- in current Python versions this would cause an unacceptable performance
271- impact.
272-
273- The exact details of the memory safety in the presence of data races
274- are likely to evolve in the future. Currently, compiled code must
275- ensure that proper synchronization is used to prevent data races. In
276- particular, these operations require explicit synchronization, such as
277- via ``threading.Lock ``, if there is a possibility of data races
278- (the list is not exhaustive):
279-
280- * Reads or writes of non-final instance data attributes of native
281- classes.
282- * List item access or iteration using a ``list `` static type (using
283- ``Sequence `` or ``MutableSequence `` as the type ensure correct
284- implicit synchronization).
285- * Dict item access using a static ``dict `` type (using ``Mapping ``
286- or ``MutableMapping `` ensures correct implicit synchronization).
268+ Mypyc supports free threading, but it doesn't provide the exact
269+ memory safety guarantees as Python in compiled modules under
270+ free threading when there are race conditions.
271+
272+ Additionally, optimized primitive operations in compiled code may have
273+ different atomicity properties compared to CPython. Use explicit
274+ synchronization if code depends on operations being atomic. This is
275+ already the recommended approach for normal Python code.
276+
277+ Currently, compiled code must ensure that proper synchronization is
278+ used to prevent data races involving non-final attributes in native
279+ classes, unless the attribute has a value type such as ``bool ``,
280+ ``float `` or ``i64 ``. You can use explicit
281+ synchronization, such as via
282+ :ref: `librt.threading.Lock <librt-threading-lock >` (or
283+ :py:class: `threading.Lock `, which is less efficient than
284+ ``librt.threading.Lock ``) if there is a possibility of such a data
285+ race.
286+
287+ .. note ::
288+
289+ We are working on improving memory safety in free-threading
290+ builds of Python, and hope to make all normal Python features
291+ memory safe, while providing more efficient but less safe
292+ opt-in, non-standard features.
287293
288294As libraries often won't be able to control the concurrent access by
289295user code, we recommend that modules document that multi-threaded
0 commit comments