News for hackers. Stuff that matters.
Re:Our Plan for Python 3.13 by tinus_hn on Thursday June 15, 2023 @02:41PM (#36344824)
The interpreter could do locks around these calls automatically to make them atomic, while leaving itself multithreaded.
Re:Our Plan for Python 3.13 by KMag on Thursday June 15, 2023 @05:12PM (#36346567)
In order for the call into C to appear atomic to a multithreaded interpreter, all threads in the interpreter would need to be blocked during the call. That's possible to do, but you've just re-introduced the GIL whenever any thread is within a C extension.

In the unlocked case, one could use low-overhead tricks used for GC safepoints in some interpreters. One low-overhead technique is a dedicated memory page from which a single byte is read at the beginning at of every opcode dispatch, and you mark that page non-readable when you need to freeze all the threads executing in the interpreter. You'd then have the SIGSEG handler block the threads until the one thread returned from C. That's fairly heavy in the case it's used, but pretty light-weight if not used.