From: daniel@dan42.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:102367] [Ruby master Feature#17592] Ractor should allowing reading shareable class instance variables
Date: Mon, 01 Feb 2021 17:43:54 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-90228.20210201174354.182@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17592.20210129152919.182@ruby-lang.org
Issue #17592 has been updated by Dan0042 (Daniel DeLorme).
That makes sense, but I'm curious about the implementation. I believe this requires synchronization of every access to a class instance variable?
----------------------------------------
Feature #17592: Ractor should allowing reading shareable class instance variables
https://bugs.ruby-lang.org/issues/17592#change-90228
* 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/
next prev parent reply other threads:[~2021-02-01 17:44 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` daniel [this message]
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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-90228.20210201174354.182@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).