3 ms·
Even pure python code could have race conditions with the GIL disabled. Stuff like accessing and modifying a dictionary item in python code is assumed and curr
by qbasic_forever 3y ago
Even pure python code could have race conditions with the GIL disabled. Stuff like accessing and modifying a dictionary item in python code is assumed and currently guaranteed to be atomic because of the GIL. Remove the GIL and decades of assumptions break.
- kzrdude 3y agoI think that's a misconception? At least the way how I understood this issue. Things like `map[k] = v` would be atomic both before and after nogil, and things like `map[k] += 1` are not atomic even with GIL, the read and store can be split from each other.
- samus 3y agoThe GIL doesn't serialize the execution of threads, but ensures only one executes at a time. Therefore, the race condition issues you describe already exist even with the GIL. The GIL is only there to ensure that the interpreter doesn't corrupt Python objects and its internal data structures, which in the best case leads to a crash.
- imtringued 3y agoCome on, think about it harder. Do you really think this would even have a chance of becoming a PEP if python code was affected? If you thought even a little bit about it, then you would have come to the very simple conclusion "no" but here we are.
- paulddraper 3y agoIn Python, race conditions with the GIL will be race conditions without the GIL, and vice versa. ....I believe so. E.g. there's no plan to make lists, dicts, thread unsafe.
- kzrdude 3y agoBut it's going to be much easier to demonstrate data consistency issues and bugs due to threading