ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
@ 2022-11-26 23:52 fxn (Xavier Noria)
  2022-11-27  0:01 ` [ruby-core:111028] " fxn (Xavier Noria)
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: fxn (Xavier Noria) @ 2022-11-26 23:52 UTC (permalink / raw)
  To: ruby-core

Issue #19154 has been reported by fxn (Xavier Noria).

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154

* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:111028] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
@ 2022-11-27  0:01 ` fxn (Xavier Noria)
  2022-12-01 13:00 ` [ruby-core:111128] " alanpowel47 (Alan Powel)
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fxn (Xavier Noria) @ 2022-11-27  0:01 UTC (permalink / raw)
  To: ruby-core

Issue #19154 has been updated by fxn (Xavier Noria).


Besides this particular error, I am wondering about concurrency guarantees in parallel requires to the same file, or parallel references to a constant for which there is an autoload.

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154#change-100281

* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:111128] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
  2022-11-27  0:01 ` [ruby-core:111028] " fxn (Xavier Noria)
@ 2022-12-01 13:00 ` alanpowel47 (Alan Powel)
  2023-01-15  1:33 ` [ruby-core:111814] " luke-gru (Luke Gruber) via ruby-core
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: alanpowel47 (Alan Powel) @ 2022-12-01 13:00 UTC (permalink / raw)
  To: ruby-core

Issue #19154 has been updated by alanpowel47 (Alan Powel).


The add(E e) method of Queue Interface inserts the element passed in the parameter to the end of the queue if there is space. If the Queue is capacity restricted and no space is left for insertion, it returns an IllegalStateException. The function returns true on successful insertion. Syntax:

boolean add(E e)
Parameters: This method accepts a mandatory parameter e which is the element to be inserted in the end of the Queue. Returns: This method returns true on successful insertion. Exceptions: The function throws four exceptions which are described as below:

ClassCastException: when the class of the element to be entered prevents it from being added to this container.
IllegalStateException: when the capacity of the container is full and insertion is done.
IllegalArgumentException: when some property of the element prevents it to be added to the queue.
NullPointerException: when the element to be inserted is passed as null and the Queue’s interface does not allow null elements.
Below programs illustrate add() method of Queue: Program 1: With the help of LinkedList. 


// Java Program Demonstrate add()
// method of Queue
 
import java.util.*;
 
public class GFG {
    public static void main(String[] args)
        throws IllegalStateException
    {
 
        // create object of Queue
        Queue<Integer> Q
            = new LinkedList<Integer>();
 
        // Add numbers to end of Queue
        Q.add(7855642);
        Q.add(35658786);
        Q.add(5278367);
        Q.add(74381793);
 
        // before removing print queue
        System.out.println("Queue: " + Q);
    }
}
Output:
Program 2: With the help of ArrayDeque. 


// Java Program Demonstrate add()
// method of Queue
 
import java.util.*;
 
public class GFG {
    public static void main(String[] args)
        throws IllegalStateException
    {
 
        // create object of Queue
        Queue<Integer> Q
            = new ArrayDeque<Integer>();
 
        // Add numbers to end of Queue
        Q.add(7855642);
        Q.add(35658786);
        Q.add(5278367);
        Q.add(74381793);
 
        // before removing print queue
        System.out.println("Queue: " + Q);
    }
}
Output:
Queue: [7855642, 35658786, 5278367, 74381793]
Program 3: With the help of LinkedBlockingDeque. 


// Java Program Demonstrate add()
// method of Queue
 
import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;
 
public class GFG {
    public static void main(String[] args)
        throws IllegalStateException
    {
 
        // create object of Queue
        Queue<Integer> Q
            = new LinkedBlockingDeque<Integer>();
 
        // Add numbers to end of Queue
        Q.add(7855642);
        Q.add(35658786);
        Q.add(5278367);
        Q.add(74381793);
 
        // before removing print queue
        System.out.println("Queue: " + Q);
    }
}
Output:
Queue: [7855642, 35658786, 5278367, 74381793]
Program 4: With the help of ConcurrentLinkedDeque. 


// Java Program Demonstrate add()
// method of Queue
 
import java.util.*;
import java.util.concurrent.ConcurrentLinkedDeque;
 
public class GFG {
    public static void main(String[] args)
        throws IllegalStateException
    {
 
        // create object of Queue
        Queue<Integer> Q
            = new ConcurrentLinkedDeque<Integer>();
 
        // Add numbers to end of Queue
        Q.add(7855642);
        Q.add(35658786);
        Q.add(5278367);
        Q.add(74381793);
 
        // before removing print queue
        System.out.println("Queue: " + Q);
    }
}
Output:
Queue: [7855642, 35658786, 5278367, 74381793]
Below programs illustrate exceptions thrown by this method: Program 5: To show NullPointerException. 


// Java Program Demonstrate add()
// method of Queue when Null is passed
 
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
 
public class GFG {
    public static void main(String[] args)
        throws IllegalStateException
    {
 
        // create object of Queue
        Queue<Integer> Q
            = new LinkedBlockingQueue<Integer>();
 
        // Add numbers to end of Queue
        Q.add(7855642);
        Q.add(35658786);
        Q.add(5278367);
 
        try {
            // when null is inserted
            Q.add(null);
        }
        catch (Exception e) {
            System.out.println("Exception: " + e);
        }
    }
}
Output:
Exception: java.lang.NullPointerException
Program 6: To show IllegalStateException. 


// Java Program Demonstrate add()
// method of Queue when capacity is full
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
 
public class GFG {
    public static void main(String[] args)
        throws IllegalStateException
    {
 
        // create object of Queue
        Queue<Integer> Q
            = new LinkedBlockingQueue<Integer>(3);
 
        // Add numbers to end of Queue
        Q.add(7855642);
        Q.add(35658786);
        Q.add(5278367);
 
        try {
            // when capacity is full
            Q.add(10);
        }
        catch (Exception e) {
            System.out.println("Exception: " + e);
        }
    }
}
Output:
Exception: java.lang.IllegalStateException: Queue full

For the UiPath.Core.Activities.AddQueueItem activity to work in a process, the Robot must be connected to Orchestrator. This is needed in order to send and retrieve information about queues, items and statuses.
Schema definition values added to queues in Orchestrator and marked as required are automatically imported in the Dictionary Builder of the activity.
Values marked as not required can be added to queue items and not be enforced.
Project compatibility
Windows - Legacy | Windows | Cross-platform

Windows, Cross-platform configuration
Orchestrator folder path - The path of the folder where the specified queue is located, if different from the folder where the process is running. This field only supports string values, with / as the separator to indicate subfolders. For example "Finance/Accounts Payable".
📘
Note:

The Orchestrator folder path parameter does not work for processes executed by robots in classic folders. Only robots in modern folders have the ability to pass data outside of their folder.

Relative folder paths are supported in an X-UIPATH-FolderPath-Encoded header, as follows:
 Path starting with / - starts from the root folder of the tree the ambient folder is part of.
 Path starting with . - starts from the ambient folder.
 Path starting with .. - starts one level up in the hierarchy of the ambient folder for each .. in the path (e.g. ../ for one level up, ../../ for two levels up in the hierarchy).

Note that trailing slashes are not accepted.

Queue Name - The queue where the QueueItem object is to be added. The name is case insensitive, meaning that if in Orchestrator it was defined as "MyFirstQueue", it matches "myfirstqueue". The maximum number of characters is 50.
Item Information - A collection of additional information about the specific QueueItem that is to be added. The information is stored in the item and is used during a transaction processing. It is recommended to use only primitive values of the following types: Number, Boolean, String and DateTime. The value of string arguments cannot contain the following characters: [ and " ". Argument names cannot contain the following characters: :, ., ,, @, ".
Advanced options. Basically I have to add the UIPATH while working on the react native development agency(https://enterprise.affle.com/react-native-app-development) , then I have to learned the same.
Input
Deadline - The date before which the queue item should be processed. This property is a criterion for the prioritization of queue items, alongside Priority and Postpone. This property can be filled in with relative dates such as DateTime.Now.AddHours(2), DateTime.Now.AddDays(10) and DateTime.Now.Add(New System.TimeSpan(5, 0, 0, 0)). Additionally, you can use the US notation to add an exact time, such as 12/10/2017 07:40:00. Automatically correcting this date is available. For example, if you write 8 9 2018 9:0, it is automatically transformed to 08/09/2018 09:00:00.
Item Collection - Enables importing an entire dictionary of information for a queue item. This field only accepts Dictionary<string, object> variables.
Postpone - The date after which the queue item may be processed. This property is a criterion for the prioritization of queue items, alongside Priority and Deadline. This property can be filled in with relative dates such as DateTime.Now.AddHours(2), DateTime.Now.AddDays(10) and DateTime.Now.Add(New System.TimeSpan(5, 0, 0, 0)). Additionally, you can use the US notation to add an exact time, such as 12/10/2017 07:40:00. Automatically correcting this date is available. For example, if you write 8 9 2018 9:0, it is automatically transformed to 08/09/2018 09:00:00.
Priority - The priority level of the queue item to be added. This property is a criterion for the prioritization of queue items, alongside Deadline and Postpone.
Reference - The reference of the added QueueItem. The reference can be used to link your transactions to other applications used within an automation project. Additionally, this feature enables you to search for certain transactions, in Orchestrator, according to the provided string.
📘
Note:

DueDate is a reserved keyword. It cannot be used inside any property when configuring this activity.

Misc
Timeout (milliseconds) - Specifies the amount of time (in milliseconds) to wait for the activity to run before an error is thrown. The default value is 30000 milliseconds (30 seconds).
Continue on error - Specifies if the automation should continue even when the activity throws an error. This field only supports Boolean values (True, False). The default value is False. As a result, if the field is blank and an error is thrown, the execution of the project stops. If the value is set to True, the execution of the project continues regardless of any error.
📘
Note:

If this activity is included in Try Catch and the value of the Continue On Error property is True, no error is caught when the project is executed.

Windows - Legacy configuration
Properties panel
Common
Continue On Error - Specifies if the automation should continue even when the activity throws an error. This field only supports Boolean values (True, False). The default value is False. As a result, if the field is blank and an error is thrown, the execution of the project stops. If the value is set to True, the execution of the project continues regardless of any error.
📘
Note:

If this activity is included in Try Catch and the value of the Continue On Error property is True, no error is caught when the project is executed.

DisplayName - The display name of the activity.
Timeout (milliseconds) - Specifies the amount of time (in milliseconds) to wait for the activity to run before an error is thrown. The default value is 30000 milliseconds (30 seconds).
Input
Deadline - The date before which the queue item should be processed. This property is a criterion for the prioritization of queue items, alongside Priority and Postpone. This property can be filled in with relative dates such as DateTime.Now.AddHours(2), DateTime.Now.AddDays(10) and DateTime.Now.Add(New System.TimeSpan(5, 0, 0, 0)). Additionally, you can use the US notation to add an exact time, such as 12/10/2017 07:40:00. Automatically correcting this date is available. For example, if you write 8 9 2018 9:0, it is automatically transformed to 08/09/2018 09:00:00.
Item Collection - Enables importing an entire dictionary of information for a queue item. This field only accepts Dictionary<string, object> variables.

Item Information - A collection of additional information about the specific QueueItem that is to be added. The information is stored in the item and is used during a transaction processing. It is recommended to use only primitive values of the following types: Number, Boolean, String and DateTime. The value of string arguments cannot contain the following characters: [ and " ". Argument names cannot contain the following characters: :, ., ,, @, ".
Postpone - The date after which the queue item may be processed. This property is a criterion for the prioritization of queue items, alongside Priority and Deadline. This property can be filled in with relative dates such as DateTime.Now.AddHours(2), DateTime.Now.AddDays(10) and DateTime.Now.Add(New System.TimeSpan(5, 0, 0, 0)). Additionally, you can use the US notation to add an exact time, such as 12/10/2017 07:40:00. Automatically correcting this date is available. For example, if you write 8 9 2018 9:0, it is automatically transformed to 08/09/2018 09:00:00.
Priority - The priority level of the queue item to be added. This property is a criterion for the prioritization of queue items, alongside Deadline and Postpone.
Queue Name - The queue where the QueueItem object is to be added. The name is case insensitive, meaning that if in Orchestrator it was defined as "MyFirstQueue", it matches "myfirstqueue". The maximum number of characters is 50.
Reference - The reference of the added QueueItem. The reference can be used to link your transactions to other applications used within an automation project. Additionally, this feature enables you to search for certain transactions, in Orchestrator, according to the provided string.
📘
Note

DueDate is a reserved keyword. It cannot be used inside any property when configuring this activity.

Misc
Folder Path - The path of the folder where the specified queue is located, if different from the folder where the process is running. This field only supports string values, with / as the separator to indicate subfolders. For example "Finance/Accounts Payable".
📘
Note:

The Folder Path parameter does not work for processes executed by robots in classic folders. Only robots in modern folders have the ability to pass data outside of their folder.

Relative folder paths are supported in an X-UIPATH-FolderPath-Encoded header, as follows:
 Path starting with / - starts from the root folder of the tree the ambient folder is part of.
 Path starting with . - starts from the ambient folder.
 Path starting with .. - starts one level up in the hierarchy of the ambient folder for each .. in the path (e.g. ../ for one level up, ../../ for two levels up in the hierarchy).

Note that trailing slashes are not accepted.

Private - If selected, the values of variables and arguments are no longer logged at Verbose level.

Hope this will help everyone. 

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154#change-100406

* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:111814] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
  2022-11-27  0:01 ` [ruby-core:111028] " fxn (Xavier Noria)
  2022-12-01 13:00 ` [ruby-core:111128] " alanpowel47 (Alan Powel)
@ 2023-01-15  1:33 ` luke-gru (Luke Gruber) via ruby-core
  2023-01-15  7:54 ` [ruby-core:111817] " luke-gru (Luke Gruber) via ruby-core
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: luke-gru (Luke Gruber) via ruby-core @ 2023-01-15  1:33 UTC (permalink / raw)
  To: ruby-core; +Cc: luke-gru (Luke Gruber)

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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:111817] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
                   ` (2 preceding siblings ...)
  2023-01-15  1:33 ` [ruby-core:111814] " luke-gru (Luke Gruber) via ruby-core
@ 2023-01-15  7:54 ` luke-gru (Luke Gruber) via ruby-core
  2023-01-16 13:41 ` [ruby-core:111833] " Eregon (Benoit Daloze) via ruby-core
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: luke-gru (Luke Gruber) via ruby-core @ 2023-01-15  7:54 UTC (permalink / raw)
  To: ruby-core; +Cc: luke-gru (Luke Gruber)

Issue #19154 has been updated by luke-gru (Luke Gruber).


I've also got parallel references to constant for which there is autoload working, with a few tweaks to the VM needed.

```ruby
rs = []
autoload :C, './test3.rb'
1000.times do
  rs << Ractor.new do
    C
    C
    C
  end
end

p rs.map(&:take)
```

I guess the next thing would be allowing calls to `autoload` itself in the Ractors, but I don't think this is going to be hard.

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154#change-101224

* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:111833] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
                   ` (3 preceding siblings ...)
  2023-01-15  7:54 ` [ruby-core:111817] " luke-gru (Luke Gruber) via ruby-core
@ 2023-01-16 13:41 ` Eregon (Benoit Daloze) via ruby-core
  2023-01-16 13:59 ` [ruby-core:111835] " fxn (Xavier Noria) via ruby-core
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2023-01-16 13:41 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #19154 has been updated by Eregon (Benoit Daloze).


luke-gru (Luke Gruber) wrote in #note-2:
> As long as there's a mutex somewhere protecting these mutations it's safe. There is a mutex around rubygems require. I only had to add `Ractor.force_shareable!` to 2 or 3 places in the rubygems code 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.

That's completely unsafe. You can look at the implementation of Mutex and you can see it relies on the GVL. With Ractors there is not a single GVL, so simply said Mutex (and Monitor too) does not prevent concurrent access with Ractors.
That's one big reason why one cannot share a Mutex/Monitor.
Also sharing a Mutex/Monitor would be a clear violation of the Ractor programming model.

I think `require`/`autoload` in a Ractor should simply be forbidden (raise an exception), see #17420.
It cannot work since it needs access to $LOADED_FEATURES, and that's owned by the main Ractor and is unsafe to access for any other Ractor.

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154#change-101242

* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:111835] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
                   ` (4 preceding siblings ...)
  2023-01-16 13:41 ` [ruby-core:111833] " Eregon (Benoit Daloze) via ruby-core
@ 2023-01-16 13:59 ` fxn (Xavier Noria) via ruby-core
  2023-01-16 19:46 ` [ruby-core:111841] " Eregon (Benoit Daloze) via ruby-core
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2023-01-16 13:59 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #19154 has been updated by fxn (Xavier Noria).


> I think require/autoload in a Ractor should simply be forbidden.

That would be a resolution for this ticket.

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154#change-101246

* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:111841] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
                   ` (5 preceding siblings ...)
  2023-01-16 13:59 ` [ruby-core:111835] " fxn (Xavier Noria) via ruby-core
@ 2023-01-16 19:46 ` Eregon (Benoit Daloze) via ruby-core
  2023-01-31 16:20 ` [ruby-core:112141] " luke-gru (Luke Gruber) via ruby-core
  2023-01-31 17:02 ` [ruby-core:112145] " fxn (Xavier Noria) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2023-01-16 19:46 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #19154 has been updated by Eregon (Benoit Daloze).

Assignee set to ko1 (Koichi Sasada)

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154#change-101253

* Author: fxn (Xavier Noria)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:112141] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
                   ` (6 preceding siblings ...)
  2023-01-16 19:46 ` [ruby-core:111841] " Eregon (Benoit Daloze) via ruby-core
@ 2023-01-31 16:20 ` luke-gru (Luke Gruber) via ruby-core
  2023-01-31 17:02 ` [ruby-core:112145] " fxn (Xavier Noria) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: luke-gru (Luke Gruber) via ruby-core @ 2023-01-31 16:20 UTC (permalink / raw)
  To: ruby-core; +Cc: luke-gru (Luke Gruber)

Issue #19154 has been updated by luke-gru (Luke Gruber).


Ah okay, I see thanks Eregon, I was confused b/t VM lock and GVL.
There could be cross-ractor mutexes and monitors if they locked the VM lock, no? Then if rubygems used these, then it would be safe?
I'm not saying it's a good idea, just that it's possible :)

I imagine it's a bit of a pain to have to eager autoload everything before you start a Ractor, but if that's what needs to be done then
c'est la vie.

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154#change-101577

* Author: fxn (Xavier Noria)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

* [ruby-core:112145] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors
  2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
                   ` (7 preceding siblings ...)
  2023-01-31 16:20 ` [ruby-core:112141] " luke-gru (Luke Gruber) via ruby-core
@ 2023-01-31 17:02 ` fxn (Xavier Noria) via ruby-core
  8 siblings, 0 replies; 10+ messages in thread
From: fxn (Xavier Noria) via ruby-core @ 2023-01-31 17:02 UTC (permalink / raw)
  To: ruby-core; +Cc: fxn (Xavier Noria)

Issue #19154 has been updated by fxn (Xavier Noria).


> I imagine it's a bit of a pain to have to eager autoload everything before you start a Ractor, but if that's what needs to be done then
c'est la vie.

This is a delicate point, in my view, because you cannot eager load what you do not control. And you do not control when your Ractor needs to invoke 3rd party APIs.

----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154#change-101581

* Author: fxn (Xavier Noria)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* 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.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'

<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
        from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
        from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
        from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
        from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>: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 <main>'
```

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/

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

end of thread, other threads:[~2023-01-31 17:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26 23:52 [ruby-core:111027] [Ruby master Bug#19154] Specify require and autoload guarantees in ractors fxn (Xavier Noria)
2022-11-27  0:01 ` [ruby-core:111028] " fxn (Xavier Noria)
2022-12-01 13:00 ` [ruby-core:111128] " alanpowel47 (Alan Powel)
2023-01-15  1:33 ` [ruby-core:111814] " luke-gru (Luke Gruber) via ruby-core
2023-01-15  7:54 ` [ruby-core:111817] " luke-gru (Luke Gruber) via ruby-core
2023-01-16 13:41 ` [ruby-core:111833] " Eregon (Benoit Daloze) via ruby-core
2023-01-16 13:59 ` [ruby-core:111835] " fxn (Xavier Noria) via ruby-core
2023-01-16 19:46 ` [ruby-core:111841] " Eregon (Benoit Daloze) via ruby-core
2023-01-31 16:20 ` [ruby-core:112141] " luke-gru (Luke Gruber) via ruby-core
2023-01-31 17:02 ` [ruby-core:112145] " fxn (Xavier Noria) via ruby-core

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).