ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:102305] [Ruby master Feature#17592] Ractor should allowing reading shareable class instance variables
@ 2021-01-29 15:29 marcandre-ruby-core
  2021-01-29 15:31 ` [ruby-core:102306] " marcandre-ruby-core
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: marcandre-ruby-core @ 2021-01-29 15:29 UTC (permalink / raw)
  To: ruby-core

Issue #17592 has been reported by marcandre (Marc-Andre Lafortune).

----------------------------------------
Feature #17592: Ractor should allowing reading shareable class instance variables
https://bugs.ruby-lang.org/issues/17592

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
----------------------------------------
It would be very helpful if Ractor was allowing reading class instance variables from non-main Ractor.


Currently is raises an IsolationError:

```ruby
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)



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2021-10-22 16:36 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 15:29 [ruby-core:102305] [Ruby master Feature#17592] Ractor should allowing reading shareable class instance variables marcandre-ruby-core
2021-01-29 15:31 ` [ruby-core:102306] " marcandre-ruby-core
2021-01-29 15:41 ` [ruby-core:102307] " eregontp
2021-01-29 17:03 ` [ruby-core:102308] " marcandre-ruby-core
2021-01-30 21:59 ` [ruby-core:102327] " joeydwong
2021-01-30 22:56 ` [ruby-core:102328] " marcandre-ruby-core
2021-02-01 16:58 ` [ruby-core:102363] " daniel
2021-02-01 17:13 ` [ruby-core:102365] " eregontp
2021-02-01 17:17 ` [ruby-core:102366] " marcandre-ruby-core
2021-02-01 17:43 ` [ruby-core:102367] " daniel
2021-02-01 18:11 ` [ruby-core:102368] " marcandre-ruby-core
2021-02-01 19:07 ` [ruby-core:102370] " eregontp
2021-02-01 19:27 ` [ruby-core:102371] " eregontp
2021-02-15  9:35 ` [ruby-core:102498] " ko1
2021-02-15  9:42 ` [ruby-core:102499] " ko1
2021-02-15 16:49 ` [ruby-core:102507] " eregontp
2021-02-16  2:14 ` [ruby-core:102512] " ko1
2021-02-16 12:45 ` [ruby-core:102537] " eregontp
2021-02-16 20:29 ` [ruby-core:102546] " marcandre-ruby-core
2021-02-16 23:26 ` [ruby-core:102547] " eregontp
2021-02-16 23:33 ` [ruby-core:102548] " eregontp
2021-02-17  0:20 ` [ruby-core:102549] " marcandre-ruby-core
2021-02-17  0:24 ` [ruby-core:102550] " marcandre-ruby-core
2021-02-24 17:12 ` [ruby-core:102594] " marcandre-ruby-core
2021-10-22 16:33 ` [ruby-core:105753] " ko1 (Koichi Sasada)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).