Feature #19346
closedAdd Ractor escape hatch Ractor.disable_isolation_checks! { }
Description
It would be nice to be able to autoload constants inside Ractors. I'm not sure why this is disabled right now because if autoloading is working properly inside threads
then my initial thought is that the autoload implementation should work inside Ractors.
I guess there's different parts to this:
registering the autoload:
Ractor.new { autoload :MyClass, 'myclass' }
Kicking off the autoload require
Ractor.new { MyClass }
This leads to the problem of calling rubygems require
inside Ractors, as rubygems is not Ractor safe.
However, it's thread-safe so it should be able to be ractor safe too (we don't need the ractor isolation checks in rubygems require).
What if there was an API:
Ractor.disable_isolation_checks! do
"..."
end
It would disable all Ractor isolation errors inside the block. Rubygems could be patched easily and other gems too that
are thread-safe and use synchronization around the class ivars and constants.
Of course it could be abused and would have to be used properly. Well it's just an idea, I'm sure other people have had the same idea before.
Updated by luke-gru (Luke Gruber) over 1 year ago
- Subject changed from Add Ractor escape Ractor.disable_isolation_checks! { } to Add Ractor escape hatch Ractor.disable_isolation_checks! { }
Updated by ko1 (Koichi Sasada) over 1 year ago
- Status changed from Open to Rejected
This kind of escape hatch can break the Ractor's assumptions so it is not accepted.
For example, we are working on making ractor-local GC and in this case an object can not be reached from other ractors without special sharing logic.
BTW rubygems is thread safe because it uses Mutex (and so on) and this kind of synchronizations are only available in a ractor.
Updated by luke-gru (Luke Gruber) over 1 year ago
Hi, thank you for replying. Rubygems is thread-safe but it doesn't work calling require
inside a non-main ractor because the rubygems internal logic doesn't follow strict isolation protocol.