SigmaQuan / Better-Python-59-Ways

Code Sample of Book "Effective Python: 59 Specific Ways to Write Better Pyton" by Brett Slatkin
1.39k stars 221 forks source link

Item 38 use lock to prevent data races in threads #34

Open OpetherMB opened 7 months ago

OpetherMB commented 7 months ago

i guess we should clear to the readers that += in you specific example it is an atomic operation and if you run the code multiple times you will always the right answer Counter should be 500000, found 500000, because in 3.X version of python they were consistently made to be atomic and so i guess the code is misleading especially for new readers ! i can suggest other senarios where we will have data races if you will