Data racing when using BINARY_OP and async functions #125784
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-asyncio
type-bug
An unexpected behavior, bug, or error
Bug report
Bug description:
I have encountered some racing issue when using binary_op and async functions like this:
In the
test
function, a binary operation (addition) is performed on the global variableresult
. Multiple tasks may attempt to read and update the value ofresult
. But, it seems the binary_op+=
load_global result first and then await the right-side value. The atomicity of the addition binary operation is not guaranteed. This causes the data override.This issue also occurred when using dict, update the dict value and some other cases.
Example
I'm not sure if this operation is as-designed or if this is documented behavior. Maybe this error case should be highlighted in the documentation.
cc @RF-Tar-Railt, @ProgramRipper
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: