Project

General

Profile

Actions

Feature #17592

closed

Ractor should allowing reading shareable class instance variables

Added by marcandre (Marc-Andre Lafortune) about 3 years ago. Updated over 2 years ago.

Status:
Closed
Target version:
-
[ruby-core:102305]

Description

It would be very helpful if Ractor was allowing reading class instance variables from non-main Ractor.

Currently is raises an IsolationError:

module Foo
  singleton_class.attr_accessor :config
  Foo.config = {example: 42}.freeze
end

Ractor.new { p Foo.config } # => IsolationError

This limitation makes it challenging to have an efficient way to store general configs, i.e. global data that mutated a few times when resources get loaded but it immutable afterwards, and needs to be read all the time.

Currently the only way to do this is to use a constant and use remove_const + const_set (which can not be made atomic easily).

I think that allowing reading only may be the best solution to avoid any race condition, e.g. two different Ractors that call @counter += 1.

The only 3 scenarios I see here are:
0) declare the constant hack the official way to store config-style data

  1. allow reading of instance variables for shareable objects (as long as the data is shareable)
  2. allow read-write

I prefer 1)


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #18193: Accessing global configuration from RactorsClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0