5 ms·
> The GIL doesn't prevent race conditions between individual python instructions Yes it does. Unless we mean something different?
by miraculixx 3y ago
> The GIL doesn't prevent race conditions between individual python instructions
Yes it does. Unless we mean something different?
- usrbinbash 3y ago> Yes it does. No, it doesn't. def thread_function(): # thread may lose core here value = store.get_value() # or anywhere inside get_value # or here update(value) # or anywhere inside update() # or here store.put_value(value) # or anywhere inside put_value() The GIL only makes certain internal functionality atomic. It doesn't protect the implemented logic from causing a race condition. So unless I protect store with a lock, I can already get a race condition, GIL or no GIL.
- csmpltn 3y agoThe user you're replying to is saying that the GIL is preventing multiple threads from executing Python bytecodes at once (preventing some classes of race conditions and ensuring thread safety). They are absolutely correct. The GIL doesn't solve or prevent all classes of race conditions (which can stem from complex interactions with databases, the filesystem, etc). Removing the GIL though, will only make things worse from that perspective - making the language more difficult to work with (for non-technical people). This is exactly why Python should be further simplified, and not made more complex - given the population which uses it most.
- usrbinbash 3y ago> and not made more complex The changes to the GIL don't force the average user to write threading code.