You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: peps/pep-0805.rst
+23-34Lines changed: 23 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Author: Mark Shannon <mark@hotpy.org>
4
4
Discussions-To: Pending
5
5
Status: Draft
6
6
Type: Standards Track
7
-
Created: 08-Sep-2025
7
+
Python-Version: 3.15
8
8
9
9
Abstract
10
10
========
@@ -23,11 +23,11 @@ Traditionally, CPython has executed in only a single thread of execution at once
23
23
This has always been seen as a limitation of Python and there has been a desire for
24
24
Python to support parallel execution for many years.
25
25
26
-
PEP 703, Making the Global Interpreter Lock Optional in CPython, and PEP 554, Multiple Interpreters in the Stdlib, offer ways to support parallelism.
26
+
:pep:`703`, Making the Global Interpreter Lock Optional in CPython, and :pep:`554`, Multiple Interpreters in the Stdlib, offer ways to support parallelism.
27
27
Multiple interpreters are both safe and support parallelism, but they are difficult to use and sharing objects
28
28
between multiple interpreters without copying is impossible.
29
29
PEP 703 supports parallel execution and sharing, but is unsafe as it allows race conditions.
30
-
Race conditions allow dangerous and hard to find bugs. In the most extreme example, Therac-25 [1]_, a race condition bug resulted in several fatalities. The trouble with race conditions is not that the bugs they introduce are necessarily worse than other bugs,
30
+
Race conditions allow dangerous and hard to find bugs. In the most extreme example, `Therac-25 <https://en.wikipedia.org/wiki/Therac-25>`__, a race condition bug resulted in several fatalities. The trouble with race conditions is not that the bugs they introduce are necessarily worse than other bugs,
31
31
but that they can be very hard to detect and may easily slip through testing.
32
32
33
33
Parallelism, without strong support from the language and runtime, is extremely difficult to get right:
@@ -71,7 +71,7 @@ The PEP also proposes changes to CPython to prevent unsafe execution when mutabl
71
71
Finally, the PEP provides a generalization of the GIL to allow incrementally moving away from the GIL.
72
72
73
73
This PEP is inspired by ideas from OCaml, specifically Data Freedom à la Mode [2]_, and the Pyrona project [3]_.
74
-
Many of the necessary technologies, such as biased and deferred reference counting, have been developed for PEP 703.
74
+
Many of the necessary technologies, such as biased and deferred reference counting, have been developed for :pep:`703`.
75
75
76
76
Specification
77
77
=============
@@ -85,7 +85,7 @@ The state can be queried by looking at the ``__shared__`` attribute of an object
85
85
An object's ``__shared__`` state can be one of the following:
86
86
87
87
* Immutable: Cannot be modified, and can be safely shared between threads.
88
-
* Local: Only visible to a single thread<sup>*</sup>, and can be freely mutated by that thread.
88
+
* Local: Only visible to a single thread\ :sup:`*`, and can be freely mutated by that thread.
89
89
* Stop-the-world mutable. Mostly immutable, but can be mutated by acquiring the stop-the-world lock.
90
90
* Protected: Object is mutable, and is protected by a mutex.
91
91
* Synchronized: A special state for some builtin objects.
@@ -98,14 +98,14 @@ The ``__shared__`` attribute is read-only.
98
98
All classes, modules and functions will be *stop-the-world mutable* initially, but can be made *immutable*.
99
99
Views, iterators and other objects that depend on the internal state of other mutable objects will inherit the state of
100
100
those objects. For example, a ``listiterator`` of a *local* ``list`` will be *local*, but a ``listiterator`` of a *protected*
101
-
``list`` will be *protected*. Views and iterators of *immutable* (including STW mutable) objects will be *local* when created.
101
+
``list`` will be *protected*. Views and iterators of *immutable* (including stop-the-world mutable) objects will be *local* when created.
102
102
103
103
All objects that are not inherently immutable (like tuples or strings) will be created as *local*.
104
104
These *local* objects can later be made *immutable* or *protected*.
105
105
106
106
Dictionaries and lists will support the ability to be made stop-the-world mutable on a per-object basis.
107
107
This is to maintain the necessary immutability for performance and mutability for
108
-
backwards campatibility for objects like ``sys.modules`` and ``sys.path``.
108
+
backwards compatibility for objects like ``sys.modules`` and ``sys.path``.
109
109
110
110
The stop-the-world lock
111
111
-----------------------
@@ -123,11 +123,11 @@ SuperThread objects
123
123
A new class ``SuperThread`` will be added to help port applications using the GIL
124
124
and sub-interpreters. All threads sharing a ``SuperThread`` will be serialized,
125
125
in the same way as all threads are currently serialized by the GIL.
126
-
``SuperThread``\ s offer much the same capabilites as sub-interpreters,
126
+
``SuperThread``\ s offer much the same capabilities as sub-interpreters,
127
127
but more efficiently and with the ability to share more objects.
128
128
129
129
There is a many-to-one relationship between threads and ``SuperThread``\ s.
130
-
If no super thread is explictly specified when creating a thread,
130
+
If no super thread is explicitly specified when creating a thread,
131
131
a new super thread will be created specifically for that thread.
132
132
The super thread of a thread cannot be changed.
133
133
@@ -215,7 +215,7 @@ Passing mutable values between threads
215
215
''''''''''''''''''''''''''''''''''''''
216
216
217
217
The ``Channel`` class is provided for passing objects from one thread to another.
218
-
The ``Channel`` class acts like a ``deque`` but handles tranferring of ownership local objects.
218
+
The ``Channel`` class acts like a ``deque`` but handles transferring of ownership local objects.
219
219
When passing a *local* object, ``channel.put(obj)`` detaches the object ``obj`` from the current thread.
220
220
When passing a *local* object, ``Channel.put()`` will fail, raising a ``ValueError``, if there are any other references to the argument.
221
221
``Channel.get()`` returns the object passed but to ``Channel.put()``, making the calling
@@ -234,7 +234,7 @@ the ``sys`` module is deleted. The main thread's ``SuperThread`` will be the GIL
234
234
235
235
If the environment variable ``PYTHONGIL=1`` is set, then all new threads will default to
236
236
``super_thread = sys.gil``. Otherwise all new threads will default to ``super_thread = None``.
237
-
Explictly setting the ``super_thread`` argument when creating a thread will override these defaults.
237
+
Explicitly setting the ``super_thread`` argument when creating a thread will override these defaults.
238
238
239
239
Deadlock detection
240
240
------------------
@@ -265,14 +265,14 @@ If we do that, then all other operations become safe.
265
265
| All other operations | Yes | Yes | N/A | Yes | Yes |
It is the author's opinion that attempting to preserve single-threaded performance
463
463
for mutable objects *and* any sort of thread safe parallel execution for the same object is wishful thinking.
@@ -475,7 +475,7 @@ Object state
475
475
476
476
Recording object state requires space in the object header, at least 3 bits but no more than a byte.
477
477
Each object also needs additional space to refer to its thread, or protecting mutex.
478
-
With these fields, the ``PyObject`` header should be the smaller than is currently implemented for PEP 703,
478
+
With these fields, the ``PyObject`` header should be the smaller than is currently implemented for :pep:`703`,
479
479
although larger than for the default (with GIL) build.
480
480
481
481
A possible object header:
@@ -543,11 +543,11 @@ Possible future enhancements
543
543
Deep freezing and deep transfers
544
544
--------------------------------
545
545
546
-
Freezing a single object could leave a frozen object with references to mutable objects, and transfering of single objects could leave an object local to one thread, while other objects that it refers to are local to a different thread.
546
+
Freezing a single object could leave a frozen object with references to mutable objects, and transferring of single objects could leave an object local to one thread, while other objects that it refers to are local to a different thread.
547
547
Either of these scanarios are likely to lead to runtime errors. To avoid that problem we need "deep" freezing.
548
548
549
549
Deep freezing an object would freeze that object and the transitive closure of other mutable objects referred to by that object.
550
-
Deep transfering an object would transfer that object and the transitive closure of other local objects referred to by that object,
550
+
Deep transferring an object would transfer that object and the transitive closure of other local objects referred to by that object,
551
551
but would raise an exception if one of the those objects belonged to a different thread.
552
552
553
553
Similar to freezing, a "deep" put mechanism could be added to ``Channel``\ s to move a whole graph of objects from one thread
@@ -565,17 +565,6 @@ Open Issues
565
565
[Any points that are still being decided/discussed.]
0 commit comments