r/ruby • • 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.

10 Upvotes

29 comments sorted by

View all comments

Show parent comment

1

u/h0rst_ 2d ago

I think it's useful to learn why C Ruby has these limitations (ie the C)

Are you trying to say that this limitation exists in CRuby because it is written in C? That's not why the GVL exists.

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. 

2

u/Edthal01 1d ago

still more to read later, after I learn Ruby better