ruby/test/prism
Koichi Sasada ef2bb61018 Ractor::Port
* Added `Ractor::Port`
  * `Ractor::Port#receive` (support multi-threads)
  * `Rcator::Port#close`
  * `Ractor::Port#closed?`
* Added some methods
  * `Ractor#join`
  * `Ractor#value`
  * `Ractor#monitor`
  * `Ractor#unmonitor`
* Removed some methods
  * `Ractor#take`
  * `Ractor.yield`
* Change the spec
  * `Racotr.select`

You can wait for multiple sequences of messages with `Ractor::Port`.

```ruby
ports = 3.times.map{ Ractor::Port.new }
ports.map.with_index do |port, ri|
  Ractor.new port,ri do |port, ri|
    3.times{|i| port << "r#{ri}-#{i}"}
  end
end

p ports.each{|port| pp 3.times.map{port.receive}}

```

In this example, we use 3 ports, and 3 Ractors send messages to them respectively.
We can receive a series of messages from each port.

You can use `Ractor#value` to get the last value of a Ractor's block:

```ruby
result = Ractor.new do
  heavy_task()
end.value
```

You can wait for the termination of a Ractor with `Ractor#join` like this:

```ruby
Ractor.new do
  some_task()
end.join
```

`#value` and `#join` are similar to `Thread#value` and `Thread#join`.

To implement `#join`, `Ractor#monitor` (and `Ractor#unmonitor`) is introduced.

This commit changes `Ractor.select()` method.
It now only accepts ports or Ractors, and returns when a port receives a message or a Ractor terminates.

We removes `Ractor.yield` and `Ractor#take` because:
* `Ractor::Port` supports most of similar use cases in a simpler manner.
* Removing them significantly simplifies the code.

We also change the internal thread scheduler code (thread_pthread.c):
* During barrier synchronization, we keep the `ractor_sched` lock to avoid deadlocks.
  This lock is released by `rb_ractor_sched_barrier_end()`
  which is called at the end of operations that require the barrier.
* fix potential deadlock issues by checking interrupts just before setting UBF.

https://bugs.ruby-lang.org/issues/21262
2025-05-31 04:01:33 +09:00
..
api [ruby/prism] Support forwarding flags on scopes 2025-01-14 20:31:38 +00:00
encoding [ruby/prism] Frozen strings in the AST 2025-01-12 18:41:42 +00:00
errors [ruby/prism] Accept a newline after the defined? keyword 2025-03-30 13:22:41 -04:00
fixtures [ruby/prism] Fix parsing rescued exception via indexed assignment 2025-04-12 17:43:57 +00:00
result [ruby/prism] Mark Prism as ractor-safe 2025-03-19 21:11:57 +00:00
ruby [ruby/prism] Be explicit in tests which files parser can't parse 2025-04-02 20:53:34 +00:00
bom_test.rb [ruby/prism] Tests overhaul 2024-05-30 15:18:20 -04:00
errors_test.rb [ruby/prism] No writing to numbered parameters 2025-02-13 20:04:02 +00:00
fixtures_test.rb [ruby/prism] Import code samples for Ruby 3.3 from the parser gem 2025-01-11 19:09:05 -05:00
fuzzer_test.rb [ruby/prism] Tests overhaul 2024-05-30 15:18:20 -04:00
heredoc_dedent_test.rb [ruby/prism] Tests overhaul 2024-05-30 15:18:20 -04:00
lex_test.rb [ruby/prism] Further refine string handling in the parser translator 2025-03-18 13:36:53 -04:00
library_symbols_test.rb [ruby/prism] Tests overhaul 2024-05-30 15:18:20 -04:00
locals_test.rb [ruby/prism] Fix up locals test with it parameters 2025-02-14 17:32:58 +00:00
magic_comment_test.rb [ruby/prism] Handle single global variable character name 2024-10-03 17:43:11 +00:00
newline_offsets_test.rb [ruby/prism] Tests overhaul 2024-05-30 15:18:20 -04:00
newline_test.rb [ruby/prism] Move Node#type and Node::type documentation 2024-07-11 14:25:54 -04:00
onigmo_test.rb [ruby/prism] Parse all regular expressions 2024-06-05 14:40:03 -04:00
percent_delimiter_string_test.rb [ruby/prism] Decode %r like % strings 2024-12-12 00:42:44 +00:00
ractor_test.rb Ractor::Port 2025-05-31 04:01:33 +09:00
regexp_test.rb [ruby/prism] Fix use of uninitialized value when parsing regexp 2024-11-12 14:19:46 +00:00
snippets_test.rb [ruby/prism] Fix binary encoding for the parser translator 2025-01-12 00:49:54 +00:00
test_helper.rb [ruby/prism] Move snapshots 2025-03-27 20:14:36 +00:00
unescape_test.rb [ruby/prism] Turn off unescape tests for Ruby >= 3.4.0 2024-12-27 01:26:54 +00:00
version_test.rb [ruby/prism] Accept version shorthand like 3.4 2024-09-24 13:21:36 +00:00