
Antoine Pitrou skrev:
- protect (somehow) the GC when collecting, so that things don't get modified under its feet
The GC would have to temporarily suspend all active threads registered with the interpreter. E.g. using the SuspendThread function in Windows API.
- protect INCREFs and DECREFs
Update using CAS (I just showed you C code for this).
- protect all mutable types (dicts being probably the most performance-critical, since they are used for namespaces and class/object attributes and methods)
CAS. Lock-free lists and hash tables exist. We don't need locks to protect mutable types and class objects. Just use a lock-free hash-table for __dict__ or whatever.
- protect all static/global data in C modules which have them
Reacquire the GIL before calling functions in C extensions functions. The GIL is nice there, but not anywhere else.
An interesting experiment would be to add all those protections without even attempting to remove the GIL, and measure the overhead compared to a regular Python. Yes, one could add a nonsence CAS to existing incref/decref, and measure overhead.