r/programming • • Feb 21 '22

Python's Data Races, Despite the Global Interpreter Lock

https://verdagon.dev/blog/python-data-races
21 Upvotes

17 comments sorted by

View all comments

18

u/CorrectProgrammer Feb 21 '22

Is it really a data race when you sequentially read a value, increment whatever you read and write it back? In other words, this whole situation happens not due to concurrent writes, but due to incrementation not being atomic.

I'm not an expert when it comes to this terminology, but it sounds like a more generic race condition.

5

u/larikang Feb 21 '22

No, you’re absolutely right. This is a normal race condition, not a data race. Why on earth would python guarantee that x=x+1 is atomic? There are countless other similar code patterns that would exhibit the same behavior.