[Python-ideas] Remove GIL with CAS instructions?
Adam Olsen
rhamph at gmail.com
Wed Oct 21 00:08:01 CEST 2009
On Tue, Oct 20, 2009 at 15:24, Sturla Molden <sturla at molden.no> wrote:
> There are lock-free data structures of any conceivable sort. There are
> multithreaded garbage collectors in Java and .NET, that don't need a global
> lock. I've heard claims that removal of the GIL would require Python to use
> a garbage collector instead of reference counts. That is not true. Lock-free
> data structures and garbage collectors have all one thing in common: they
> use a compare-and-exchange (CAS) instruction present in most modern
> processors, e.g. CMPXCHG on x86. In fact, CAS is used to implement OS
> mutexes (sleeplocks) and the less expensive spinlocks. Without a CAS
> instruction for the platform, there would be no GIL. All platforms that has
> a working GIL has a working CAS.
CPython uses *extensive* refcounting operations on objects shared
between threads (builtins, globals, literals, etc). The cache
contention over those refcounts means even 2 threads are significantly
slower than 1 thread, nevermind the increased contention of 3+
threads. That is why it is said a true tracing GC is needed to
replace the refcounting GC.
--
Adam Olsen, aka Rhamphoryncus
More information about the Python-ideas
mailing list