Project

General

Profile

Actions

Feature #22478

open

RbConfig::CONFIG could be Ractor-shareable by default?

Feature #22478: RbConfig::CONFIG could be Ractor-shareable by default?

Added by altruby (Alt Ruby) 20 days ago. Updated 13 days ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:127254]

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 Actions #1 [ruby-core:127255]

The methods in mkmf.rb sometimes modify it.

Updated by altruby (Alt Ruby) 13 days ago Actions #2 [ruby-core:127320]

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

Also available in: PDF Atom