From: daniel@...42.com Date: 2020-10-22T14:56:41+00:00 Subject: [ruby-core:100505] [Ruby master Bug#17268] special global variables which can be accessed from ractors Issue #17268 has been updated by Dan0042 (Daniel DeLorme). Why can't ractors access global variables? Shouldn't it be like constants, where a frozen/shareable object can be accessed? ```ruby $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? ``` ---------------------------------------- Bug #17268: special global variables which can be accessed from ractors https://bugs.ruby-lang.org/issues/17268#change-88127 * Author: ko1 (Koichi Sasada) * Status: Closed * Priority: Normal * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- Ractors can't access global variables, but some special global variables should be accessed. There are several types. ## Proposal (1) Read-only global variables ```ruby # process-local (readonly): other commandline parameters '$-p' => $-p, '$-l' => $-l, '$-a' => $-a, # process-local (readonly): getpid '$$' => $$, ``` (2) scope local variables ```ruby # thread local: process result '$?' => $?, # scope local: match '$~' => $~.inspect, '$&' => $&, '$`' => $`, '$\'' => $', '$+' => $+, '$1' => $1, # scope local: last line '$_' => $_, # scope local: last backtrace '$@' => $@, '$!' => $!, ``` (3) Ractor local variables ```ruby # 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` -- https://bugs.ruby-lang.org/ Unsubscribe: