Re:Data races in Python, despite the Global Interpreter Lock
by Kranar on Monday February 21, 2022 @09:05PM
(#30423261)
There need not be any parallelism or simultaneity for a data race to occur. What matters is that writes occur concurrently with another read/write, not whether they occur in parallel.
For example it's possible on a single core CPU to have one thread operate on the higher bits of a 32-bit memory location then yield to second thread that operates on the lower 32-bits of the same memory location so that the end result is a clobbered write. At no point do the two threads run simultaneously and yet this would still be an example of a data race.
Python's GIL makes such an access impossible on any platform it runs on.
(Edited in response to your edit)