Module 25 Β· Blocks, Procs & Lambdas β Lesson 6 of 6 Β· ~9 min
Threads, Fibers & Ractors (Survey)
The GVL: the one fact that explains Ruby concurrency
Ruby (MRI/CRuby) has a Global VM Lock: only one thread executes Ruby code at a time. This sounds fatal but isn't, because the GVL is released during blocking I/O β network calls, DB queries, file reads. So threads give you real concurrency for I/O-bound work (the usual web-app case) but not parallelism for CPU-bound work.
In an interview, say: "CRuby's GVL means threads don't run Ruby code in parallel, but the lock is released on I/O β so threads win for I/O-bound work like DB and HTTP calls, which is most web work. For CPU-bound parallelism you need multiple processes or Ractors."