r/ruby • u/Edthal01 • 2d ago
Question GVL and concurrent programming
Ruby cannot perform real concurrent processing on multicore microprocessors without using ractors because of the GVL. It will only simulate multiple simultaneous processes with threads, queues, mutexes, etc. in a single processor core, no true parallel processing. How does this limitation affect true parallel programming in Ruby, that is, how much more complicated is it in producing true multicore parallel programming? I am still working on learning Ruby and this is part of my self-inflicted learning process in parallel with Huw Collingworth Book of Ruby.
View all comments
Show parent comment
2
u/CaptainKabob 2d ago
I mean that to understand concurrency in C Ruby, one should read the C Ruby implementation, which is written in C. If it was written in Fortran, you'd read it in Fortran.
The GVL does not exist because C Ruby is written in C. And also C is generally recognized as closely modeling contemporary low-level computing theory of which managing memory access/safety is important. There's a surface-level "Ruby has a GVL" and then the concrete "there is a lock right here during Ruby VM execution. And here, and here."
Jean writes good stuff: https://byroot.github.io/ruby/performance/2025/08/11/unlocking-ractors-generic-variables.html
I occasionally dip into it: https://island94.org/2025/01/ruby-thread-contention-simply-gvl-queuing#:~:text=There%E2%80%99s%20a%20very,explain%20briefly%20here:
From a learning standpoint, there is imo: learning a language to practical outcomes (writing programs), understanding the languages implementation(s), learning how the implementations and the languages have co-evolved and are still evolving, transcending that distinction to where the language and the implementation(s) and the frameworks and the programs are of the same (potential) plasticity.