Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Well, I think you can manipulate a dict from two different threads in Python, today, without any risk of segfaults.


It's memory safe, but it's not necessarily free of race conditions! It's not only C extensions that release the GIL, the Python interpreter itself releases the GIL after a certain number of instructions so that other threads can make progress. See https://docs.python.org/3/library/sys.html#sys.getswitchinte....

Certain operations that look atomic to the user are actually comprised of multiple bytecode instructions. Now, if you are unlucky, the interpreter decides to release the GIL and yield to another thread exactly during such instructions. You won't get a segfault, but you might get unexpected results.

See also https://github.com/google/styleguide/blob/91d6e367e384b0d8aa...


You can do so in free-threaded Python too, right? The dict is still protected by a lock, but one that’s much more fine-grained than the GIL.


Sounds good, yes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: