0Pricing
Ruby Academy · Lesson

The GVL Explained

Why threads are limited.

What Is the GVL?

The GVL (Global VM Lock, historically the GIL) is a lock inside CRuby, the standard Ruby interpreter.

  • It allows only one thread to execute Ruby code at a time.
  • It protects the interpreter's internals from concurrent corruption.
  • It means pure-Ruby CPU work does not truly run in parallel on multiple cores.

Understanding the GVL explains when threads help and when they do not.

Why It Exists

CRuby's internals (object allocation, garbage collection, C extensions) were not all written to be thread-safe. The GVL makes them safe by serializing Ruby execution.

Removing it cleanly is hard, so CRuby keeps it. JRuby and TruffleRuby do not have a GVL and can run threads on many cores.

All lessons in this course

  1. Threads
  2. The GVL Explained
  3. Fibers
  4. Ractors
← Back to Ruby Academy