Re:Data races in Python, despite the Global Interpreter Lock
by nneonneo on Monday February 21, 2022 @06:05PM
(#30421928)
A bit more detail: there is an atomic addition bytecode, called INPLACE_ADD, which is why something like “a_list += [1]” is actually atomic. The problem is that integers are immutable, so “counter += 1” involves a (non-atomic) load and store of counter, and that’s where the race is.
Hypothetically, if Python had a built-in mutable integer type, the increment could be made atomic.
Hypothetically, if Python had a built-in mutable integer type, the increment could be made atomic.