From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [IPv6:2a01:4f8:1c0c:6b10::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 5197E1F47C for ; Sun, 15 Jan 2023 01:33:50 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=CgEur/jy; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=G/xJ5Kln; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id B75857E5F7; Sun, 15 Jan 2023 01:33:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1673746422; bh=S7asuLgRuPo+fkVQh6EuTdThrUSzkfWNf7H4UKBap+M=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=CgEur/jy23RCPrm0z/rbsmCowvwuoewfJ7mFpEEWObWupozDD+8yA3qftv/lQvGQa gW5uEqI3cWfFy3RfmeAlmngRgoDlxWokUh8woKrud7Vd1RdHLmVjXBWbNhmdbF2AeD V7VPG7ZGqbT6dWjTeG6Y7f+Rzt2DA7+87CFBcmWI= Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 9D38D7E51C for ; Sun, 15 Jan 2023 01:33:38 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=G/xJ5Kln; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=Tp0e96S/+uaMgfDueOccXP8hTe+Cxa1uFBtq4L8YKGA=; b=G/xJ5KlncOsghibM7i59+ht5BjnUK4ADLnPP2sRHWLc7uYuvTTr6O8tQZfAReKyCGpuQ 9K9sNaygDfXMEEZ0QuSUygyFKFZONX1lDJoQLTJc44DNo81lZsR1SeICeTVao8jan5aWx6 rcNlBx3cducSXCJ/YrxE493SO9jKcmIiY1VYEKC7Bh/SnjIY1zPP9gnVpw9RVE1PvESFau BCqdVN51YVbzMDY/FAAVBcuMVqJKUS6l+lq4odQ1eO7LZnaZ3VOg6lpvO/5GJlLCwkdbvr tc1hu0G/K3x+6c+/kzE/R/ildMnofIkl0CTMIUCMsVjA+BXV7BfgwZpiZ3eYhCvQ== Received: by filterdrecv-6b9548745c-xmzqt with SMTP id filterdrecv-6b9548745c-xmzqt-1-63C357F0-10 2023-01-15 01:33:36.590740897 +0000 UTC m=+601498.668650730 Received: from herokuapp.com (unknown) by geopod-ismtpd-1-2 (SG) with ESMTP id 9CIxYtqTQ1-g8AdxMMdzzA for ; Sun, 15 Jan 2023 01:33:36.580 +0000 (UTC) Date: Sun, 15 Jan 2023 01:33:36 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 19154 X-Redmine-Issue-Author: fxn X-Redmine-Sender: luke-gru 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-Redmine-MailingListIntegration-Message-Ids: 88207 X-SG-EID: =?us-ascii?Q?NolEzGrSupqd1yGX5VUUH0FR5S3PWbtU7ykbJoN2A9NE30FctmfRpn=2F0IVp0YE?= =?us-ascii?Q?juYdxriVUH0u7=2F4zG=2FXhAZvpDD936cuEo0yAaEf?= =?us-ascii?Q?Ki69+jrEcWYWI2Ga8vfmPtoU5j=2FhbF28dlaO=2Fna?= =?us-ascii?Q?iNnkyXRP4jivpkZWLm2gpsk4GqtlsdWZecMscaV?= =?us-ascii?Q?KX8dYuYj8BUV1UyfAAbd9LTRRdDBw2ZgAlR4O7A?= =?us-ascii?Q?gzW=2FiV3MFAGBmztbqjdLUvrnIB8myS2izCxkpm+?= =?us-ascii?Q?9fk5EKZGvkI3B0Dd3uAZw=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: GXZS7NJW6ND3EPCVT6HFE6PPM6SJCD6L X-Message-ID-Hash: GXZS7NJW6ND3EPCVT6HFE6PPM6SJCD6L X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:111814] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "luke-gru (Luke Gruber) via ruby-core" Cc: "luke-gru (Luke Gruber)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #19154 has been updated by luke-gru (Luke Gruber). I've taken a look at this a bit and got this working: ```ruby require 'rubygems' # get rubygems version of require rs = [] 100.times do rs << Ractor.new do require './c.rb' end end rs.each(&:take) p C ``` In file c.rb, it's ```ruby class C puts "GOT HERE" end ``` And it works correctly, only printing "GOT HERE" once and defining C once. I've had to make several small changes to the interpreter to enable setting ivars and class variables on classes and modules. I've also added an API of `Ractor.force_shareable!(obj)` that forces the shareable flag on the object and all nested objects that it contains. This is necessary for certain objects like monitor objects and other deeply nested objects. I only had to add `Ractor.force_shareable!` to 2 or 3 places and requiring gems now works across Ractors. I didn't add any tests but I might add some if other people are interested in this work. Also I'll take a look at `autoload`. I know for some, forcing objects to be marked as shareable is a bit unsavory but as long as you know what you're doing it should be okay, like the rust escape hatch of `unsafe`. ---------------------------------------- Bug #19154: Specify require and autoload guarantees in ractors https://bugs.ruby-lang.org/issues/19154#change-101222 * Author: fxn (Xavier Noria) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0preview3 (2022-11-27) [x86_64-darwin22] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- Given a file `c.rb`: ```ruby class C end ``` the following script: ```ruby r1 = Ractor.new do require './c.rb' end r2 = Ractor.new do require './c.rb' end r1.take r2.take ``` raises: ``` % ruby -v foo.rb ruby 3.2.0preview3 (2022-11-27) [x86_64-darwin22] foo.rb:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. # terminated with exception (report_on_exception is true): # terminated with exception (report_on_exception is true): :164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError) from :167:in `require' from foo.rb:6:in `block in
' :37:in `require':164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError) from :167:in `require' can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError) from foo.rb:2:in `block in
' :37:in `require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError) from foo.rb:2:in `block in
' from foo.rb:6:in `block in
' :698:in `take': thrown by remote Ractor. (Ractor::RemoteError) from foo.rb:9:in `
' :164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError) from :167:in `require' from foo.rb:2:in `block in
' :37:in `require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError) from foo.rb:2:in `block in
' ``` Would it be possible to have documentation about their interaction? This is important also to understand autoloading within ractors, since constant references may trigger `require` calls. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/