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 E02101F4B4 for ; Mon, 1 Feb 2021 17:17:19 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C3F4F120B03; Tue, 2 Feb 2021 02:16:26 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id B3288120B02 for ; Tue, 2 Feb 2021 02:16:24 +0900 (JST) Received: by filterdrecv-p3las1-598b7f99cd-pmdtk with SMTP id filterdrecv-p3las1-598b7f99cd-pmdtk-20-6018379A-38 2021-02-01 17:17:14.338332241 +0000 UTC m=+323020.118760555 Received: from herokuapp.com (unknown) by ismtpd0041p1mdw1.sendgrid.net (SG) with ESMTP id Q5Cz8IXkTU2GMTnorWCADg for ; Mon, 01 Feb 2021 17:17:14.208 +0000 (UTC) Date: Mon, 01 Feb 2021 17:17:14 +0000 (UTC) From: marcandre-ruby-core@marc-andre.ca Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 78283 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: marcandre 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?6=2FIMxCQLDposcQf5wmbDAtfaKduBAO0bKyhL3BGZtMQ5q7K2TvpbN6A7JIyt9E?= =?us-ascii?Q?aOcwYNQD9CSiVC8NgfNee+8xxVpX8DBCnyXMfbm?= =?us-ascii?Q?Yjf0IpXX0kXf1pyXT2jwtul=2FaBvExwLSf3NSF0R?= =?us-ascii?Q?rZXG2rlVMj64hRk7ZK90br6NimrViixcf=2FAayrn?= =?us-ascii?Q?m1DcADxCLwG3eE94d=2FdDLOb435inol2bvN3h2zS?= =?us-ascii?Q?q4J5vp8O=2Fp9ty2oJ6BiuatjSkP8JOWeLnKBcw1?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 102366 Subject: [ruby-core:102366] [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 marcandre (Marc-Andre Lafortune). Right. My proposal disallows reassigning from non-main ractors. Reassigning from main Ractor to a non-shareable `data` is no problem, but future attempts to read it from non-main Ractor will result in `IsolationError` (as they do currently). ```ruby # Main ractor: String.singleton_class.attr_accessor :a String.a = [].freeze Ractor.new { p Ractor.a }.take # => [] Ractor.new { Ractor.a = nil }.take # => IsolationError (can't reassign from non-main Ractor) String.a = [] Ractor.new { p Ractor.a } # => IsolationError (can't read non-shareable from non-main Ractor) ``` ---------------------------------------- Feature #17592: Ractor should allowing reading shareable class instance variables https://bugs.ruby-lang.org/issues/17592#change-90227 * 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/