Ractors
True parallelism.
What Is a Ractor?
A Ractor (Ruby Actor) is a concurrency primitive introduced in Ruby 3 that provides true parallelism. Each Ractor runs Ruby code on its own, so two Ractors can use two CPU cores at the same time.
- Ractors do not share mutable objects, which sidesteps the GVL limitation.
- They communicate by sending messages.
Ractors are still experimental, so Ruby prints a warning when you use them.
Creating a Ractor
Create one with Ractor.new and a block. The block runs in parallel. Use take to get the block's final value.
r = Ractor.new do
2 + 3
end
puts r.take