Project

General

Profile

Actions

Bug #17268

closed

special global variables which can be accessed from ractors

Bug #17268: special global variables which can be accessed from ractors

Added by ko1 (Koichi Sasada) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:100439]

Description

Ractors can't access global variables, but some special global variables should be accessed.
There are several types.

Proposal

(1) Read-only global variables

 # process-local (readonly): other commandline parameters '$-p' => $-p, '$-l' => $-l, '$-a' => $-a, # process-local (readonly): getpid '$$' => $$, 

(2) scope local variables

 # thread local: process result '$?' => $?, # scope local: match '$~' => $~.inspect, '$&' => $&, '$`' => $`, '$\'' => $', '$+' => $+, '$1' => $1, # scope local: last line '$_' => $_, # scope local: last backtrace '$@' => $@, '$!' => $!, 

(3) Ractor local variables

 # ractor-local (derived from created ractor): debug '$DEBUG' => $DEBUG, '$-d' => $-d, # ractor-local (derived from created ractor): verbose '$VERBOSE' => $VERBOSE, '$-w' => $-w, '$-W' => $-W, '$-v' => $-v, # ractor local: stdin, out, err '$stdin' => $stdin.inspect, '$stdout' => $stdout.inspect, '$stderr' => $stderr.inspect, 

Implementation: https://github.com/ruby/ruby/pull/3670
I'll merge it soon.

Discussion

  • only accessible from main ractor?
    • $0:
    • ARGV, ARGF, $.
  • only accessible from main ractor because they will be obsolete
    • $, $/ $; $\
  • So difficult: $" / $LOADED_FEATURES and $: / $LOAD_PATH

Updated by ko1 (Koichi Sasada) about 5 years ago Actions #1

  • Description updated (diff)

Updated by ko1 (Koichi Sasada) about 5 years ago Actions #2

  • Status changed from Open to Closed

Applied in changeset git|99310e3eb56fbc85bb45119285812eb959448d0c.


Some global variables can be accessed from ractors

Some global variables should be used from non-main Ractors.
[Bug #17268]

 # ractor-local (derived from created ractor): debug '$DEBUG' => $DEBUG, '$-d' => $-d, # ractor-local (derived from created ractor): verbose '$VERBOSE' => $VERBOSE, '$-w' => $-w, '$-W' => $-W, '$-v' => $-v, # process-local (readonly): other commandline parameters '$-p' => $-p, '$-l' => $-l, '$-a' => $-a, # process-local (readonly): getpid '$$' => $$, # thread local: process result '$?' => $?, # scope local: match '$~' => $~.inspect, '$&' => $&, '$`' => $`, '$\'' => $', '$+' => $+, '$1' => $1, # scope local: last line '$_' => $_, # scope local: last backtrace '$@' => $@, '$!' => $!, # ractor local: stdin, out, err '$stdin' => $stdin.inspect, '$stdout' => $stdout.inspect, '$stderr' => $stderr.inspect, 

Updated by Dan0042 (Daniel DeLorme) about 5 years ago Actions #3 [ruby-core:100505]

Why can't ractors access global variables? Shouldn't it be like constants, where a frozen/shareable object can be accessed?

$x = [1,2,3] Ractor.new{ $x }.take # I understand that this can't work $x = true Ractor.new{ $x }.take # but why is this not ok? 

Updated by Eregon (Benoit Daloze) about 5 years ago Actions #4 [ruby-core:100509]

I think this issue is mostly about "special" global variables, not so much about "regular" global variables.

I wonder if "regular" global variables should be Ractor-local, or behave like constants.
Since most of the above became Ractor-local (instead of per-Process before) or a narrower scope, I think Ractor-local would make most sense.
The only special variables that are still process-local are read-only, which means it's the same as if they were Ractor-local read-only.

Updated by Dan0042 (Daniel DeLorme) about 5 years ago Actions #5 [ruby-core:100510]

Eregon (Benoit Daloze) wrote in #note-4:

I wonder if "regular" global variables should be Ractor-local, or behave like constants.

I wouldn't mind either way. Although if Ractor-local I would hope they are derived from created ractor, like $DEBUG and $VERBOSE.

Updated by ko1 (Koichi Sasada) about 5 years ago Actions #6 [ruby-core:100583]

The proposal is accepted.

I wonder if "regular" global variables should be Ractor-local, or behave like constants.

This is rejected at first by Matz (my original proposal is making all $gvars are ractor-local), to avoid confusion.

Actions

Also available in: PDF Atom