ruby/test
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
..
-ext- Ractor::Port 2025-05-31 04:01:33 +09:00
.excludes Do not intern invalid symbols in eval parse 2025-01-07 22:30:16 -05:00
.excludes-mmtk [ruby/mmtk] Exclude the test_ractor_parallel test with MMTk 2025-04-30 13:41:21 +00:00
.excludes-parsey Handle void expressions in defined? 2025-03-18 14:44:28 -04:00
cgi Removed CGI library without CGI::Escape features 2025-05-09 14:27:28 +09:00
coverage Fix coverage measurement for negative line numbers 2025-04-09 23:45:54 +09:00
date Ractor::Port 2025-05-31 04:01:33 +09:00
did_you_mean Ractor::Port 2025-05-31 04:01:33 +09:00
digest Ractor::Port 2025-05-31 04:01:33 +09:00
dtrace Removed Solaris conditions from test files 2025-04-02 16:24:47 +09:00
erb Inline Class#new. 2025-04-25 13:46:05 -07:00
error_highlight [ruby/error_highlight] Ensure first_line and last_line are set 2025-01-29 08:51:42 +00:00
etc Ractor::Port 2025-05-31 04:01:33 +09:00
fiber Ractor::Port 2025-05-31 04:01:33 +09:00
fileutils Removed Solaris conditions from test files 2025-04-02 16:24:47 +09:00
io Ractor::Port 2025-05-31 04:01:33 +09:00
json Ractor::Port 2025-05-31 04:01:33 +09:00
lib Assert everything is compiled in test_zjit (https://github.com/Shopify/zjit/pull/40) 2025-04-18 21:52:59 +09:00
mkmf
mmtk do not reset EnvUtil.timeout_scale 2025-03-05 05:45:54 +09:00
monitor
net Use EnvUtil.apply_timeout_scale 2025-04-03 20:03:18 +09:00
objspace Ractor::Port 2025-05-31 04:01:33 +09:00
open-uri [ruby/open-uri] Use ENV.update 2024-11-25 08:00:03 +00:00
openssl [ruby/openssl] AWS-LC has support for parsing ber constructed strings now 2025-05-15 16:40:42 +00:00
optparse [ruby/optparse] Fix completion of key-value pairs array 2025-03-17 10:18:49 +00:00
pathname Ractor::Port 2025-05-31 04:01:33 +09:00
prism Ractor::Port 2025-05-31 04:01:33 +09:00
psych Ractor::Port 2025-05-31 04:01:33 +09:00
resolv [ruby/resolv] Omit Windows and MinGW platforms with with_udp_and_tcp 2024-11-26 02:44:00 +00:00
ripper [Bug #21202] Fix wrong token concat while tokenizing nested unterminated heredoc (#13000) 2025-03-29 20:46:43 +09:00
ruby Ractor::Port 2025-05-31 04:01:33 +09:00
rubygems [rubygems/rubygems] test(ruby): fix spelling 2025-05-28 13:34:40 +09:00
socket Make Addrinfo objects Ractor shareable 2025-05-20 18:04:37 -07:00
stringio Ractor::Port 2025-05-31 04:01:33 +09:00
strscan Ractor::Port 2025-05-31 04:01:33 +09:00
uri Ractor::Port 2025-05-31 04:01:33 +09:00
win32 [ruby/win32-registry] Fix compatibility with JRuby 2024-10-17 01:51:41 +00:00
yaml [ruby/yaml] We should load rubygems for optional pstore gem 2025-01-14 04:36:25 +00:00
zlib [ruby/zlib] Don't call rb_str_set_len while released the GVL. 2024-11-20 21:02:16 +00:00
runner.rb
test_bundled_gems.rb
test_delegate.rb
test_extlibs.rb Skip to existence check fiddle from TestExtLibs 2025-02-05 07:36:59 +09:00
test_find.rb
test_forwardable.rb
test_ipaddr.rb [ruby/ipaddr] Added IPAddr#+/- 2025-04-26 11:56:42 +00:00
test_open3.rb
test_pp.rb [ruby/pp] Ensure the thread local state is always set up. 2025-02-25 03:38:04 +00:00
test_prettyprint.rb
test_pty.rb Add sleep to PTY tests to stabilize flaky failures (#12691) 2025-02-03 16:07:19 +09:00
test_rbconfig.rb Ractor::Port 2025-05-31 04:01:33 +09:00
test_securerandom.rb [ruby/securerandom] Restore SecureRandom.alphanumeric same as Random::Formatter.alphanumeric of Ruby 3.3/3.4 2024-12-16 05:35:47 +00:00
test_shellwords.rb [ruby/shellwords] NUL char cannot be in shell words 2024-12-04 07:48:59 +00:00
test_singleton.rb
test_tempfile.rb
test_time.rb Ractor::Port 2025-05-31 04:01:33 +09:00
test_timeout.rb Revert "try to show timeout sec" 2025-03-05 05:45:54 +09:00
test_tmpdir.rb Ractor::Port 2025-05-31 04:01:33 +09:00
test_trick.rb
test_tsort.rb
test_unicode_normalize.rb
test_weakref.rb