nogil violation of atomicity on set operations #126136
Labels
3.13
bugs and security fixes
3.14
new features, bugs and security fixes
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
Hi,
We're a research group focused on testing concurrent runtimes. Our work-in-progress prototype found a violation of atomicity on the current nogil build when using concurrent operations on the same set. The program below shows the wrong behavior.
A set starts with
{1,2,3,4,5,6}
and two threads each make a concurrent operation on it:intersection_update({1,5})
andsymmetric_difference_update({1, 8, 7, 5, 9})
.Depending on the order of execution, the possible results are either
{7,8,9}
or{}
(the empty set).Running the test harness above shows that the (incorrect) result
{1, 5}
is sometimes possible.If you have trouble observing this behavior, feel free to increase the first
range
's last argument to a large integer (e.g., from2000
to10000
).We replicated this bug on 3 different machines with varying numbers of cores; and we were able to find it even using a single pair of threads (i.e., the second range's argument from
100
to1
). The current harness uses 100 pairs of threads operating on unrelated sets to speed up bug discovery.We're happy to provide more details about this bug, and to help developers reproducing it.
Output of
python -VV
:Python 3.14.0a1+ experimental free-threading build (heads/main:faa3272fb8d, Oct 29 2024, 09:14:25) [GCC 14.2.1 20240805]
Example output:
@flypoodles and @overlorde are part of the team, adding them so they get notified about further discussion.
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: