I saw a link to a really interesting paper this morning: Eliminating Global Interpreter Locks in Ruby through Hardware Transactional Memory. This blew my mind when I read it as it’s a really interesting concept; let me explain.

What is Hardware Transactional Memory?


What is the GIL?

(or, How to stop concurrency problems by stopping concurrency)

Ruby2‘s GIL is a VM-wide mutex that a thread must obtain before that thread can execute Ruby code. This is necessary because C extensions and many parts of Ruby are not actually thread-safe (including Array and Hash!) By holding the GIL, we guarantee that our thread’s Ruby code is the only Ruby code executing; there can’t be any concurrency issues.3

What does TM have to do with the GIL?




That’s a very brief overview of the paper but I think it’s a fascinating idea and one worth pursuing further.

  1. HTM is available via Intel’s TSX extensions, available on some recent Haswell processors. Hopefully this will become standard in future generations of x86 CPUs.

  2. Ruby in this case means MRI. JRuby and Rubinius are thread-safe. <3

  3. As with everything, it’s more complicated than that. Concurrency != parallelism and all that; please skip the comments arguing at me, trying to win Internet points.