From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 6073B1F4B4 for ; Mon, 1 Feb 2021 16:58:26 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B1C62120AF4; Tue, 2 Feb 2021 01:57:29 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 5F147120AE6 for ; Tue, 2 Feb 2021 01:57:27 +0900 (JST) Received: by filterdrecv-p3iad2-d95cd74f-mpsbl with SMTP id filterdrecv-p3iad2-d95cd74f-mpsbl-18-60183324-22 2021-02-01 16:58:12.240594203 +0000 UTC m=+321949.938744206 Received: from herokuapp.com (unknown) by ismtpd0098p1iad2.sendgrid.net (SG) with ESMTP id rEuFXlNsSHWEmR73dM-6Ig for ; Mon, 01 Feb 2021 16:58:12.177 +0000 (UTC) Date: Mon, 01 Feb 2021 16:58:12 +0000 (UTC) From: daniel@dan42.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 78280 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17592 X-Redmine-Issue-Author: marcandre X-Redmine-Issue-Assignee: ko1 X-Redmine-Sender: Dan0042 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?8sy4RigFvRTdBfCVJrT9zb2J88PC92TMQwdNgaWYaq78aMM+xsmwEK4IBKcGoM?= =?us-ascii?Q?pu=2FxnouncQCf9AaGJcuL3i5c=2FTTGCFOTHx4gsYo?= =?us-ascii?Q?zsmPQnfnIy0seonKP8yXsJTTAxk1F1qqlLxRYnC?= =?us-ascii?Q?JMtFKHH+mYWhGZ+JrzGKkO6geywHwaklXNRltxW?= =?us-ascii?Q?LFBoiLQh+9CBzsPAvEWQBHwujNZFfgReffQ=3D=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 102363 Subject: [ruby-core:102363] [Ruby master Feature#17592] Ractor should allowing reading shareable class instance variables X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17592 has been updated by Dan0042 (Daniel DeLorme). If a class instance variable refers to a shareable object it would make sense to be able to read it in ractors. But what about reassigning the instance variable? How does the proposal work then? ```ruby ## in main ractor: @a = Ractor.make_shareable(data) # @a is readable in ractors @a = data # @a is no longer readable in ractors? assignment disallowed? ## in non-main ractor: @a = Ractor.make_shareable(data) # ??? ``` ---------------------------------------- Feature #17592: Ractor should allowing reading shareable class instance variables https://bugs.ruby-lang.org/issues/17592#change-90224 * 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/