Re:Data races in Python, despite the Global Interpreter Lock
by a-dub on Monday February 21, 2022 @06:18PM
(#30422032)
it's kind of the canonical example of a data race. down in machine code land, the instructions that implement synchronization primitives are typically of the form "check prior existing value and change the value in one atomic step."
and yes, as everyone is saying, the gil keeps the python interpreter/runtime from ending up in an inconsistent state... its behavior should not be depended on by user programs. if you need to increment a counter, use a lock, or a counter that explicitly states that it's a thread safe atomic counter on the tin.
and yes, as everyone is saying, the gil keeps the python interpreter/runtime from ending up in an inconsistent state... its behavior should not be depended on by user programs. if you need to increment a counter, use a lock, or a counter that explicitly states that it's a thread safe atomic counter on the tin.