Actions
Feature #22478
openRbConfig::CONFIG could be Ractor-shareable by default?
Feature #22478:
RbConfig::CONFIG could be Ractor-shareable by default?
Status:
Open
Assignee:
-
Target version:
-
Description
Hi
Is this intentional? The following code fails due to
Ractor::CONFIG not being Ractor-shareable.
##
# Ractor::IsolationError
require "rbconfig"
Ractor.new {
Process.wait Process.spawn(RbConfig.ruby, "-e", "p 123")
}.value
This works fine but wouldn't be backwards compatible:
require "rbconfig"
Ractor.make_shareable(RbConfig::CONFIG)
Ractor.new {
Process.wait Process.spawn(RbConfig.ruby, "-e", "p 123")
}.value
Would it be acceptable for RbConfig::CONFIG to
be deeply frozen, by default?
Thanks,
Updated by nobu (Nobuyoshi Nakada) 20 days ago
The methods in mkmf.rb sometimes modify it.
Updated by altruby (Alt Ruby) 13 days ago
Could RbConfig::RACTOR_CONFIG be added?
This works. I admit it is strange. I don't
think Ractor provides a way to do a deep
copy so RbConfig::CONFIG is copied, frozen
and returned to the main Ractor.
I don't suggest ruby do something like this,
but maybe RbConfig::RACTOR_CONFIG could be
added to the same effect.
module RbConfig
RACTOR_CONFIG = Ractor.new(RbConfig::CONFIG) { Ractor.make_shareable(it) }.value
def self.ruby
File.join(
RACTOR_CONFIG["bindir"],
RACTOR_CONFIG["ruby_install_name"] + RACTOR_CONFIG["EXEEXT"]
)
end
end
Ractor.new do
Process.wait Process.spawn(RbConfig.ruby, "-e", "p 123")
end.value
##
# All false
p RbConfig::CONFIG.frozen?
p RbConfig::CONFIG["INSTALL"].frozen?
##
# All true
p RbConfig::RACTOR_CONFIG.frozen?
p RbConfig::RACTOR_CONFIG["INSTALL"].frozen?
Actions