diff options
author | Koichi Sasada <[email protected]> | 2023-04-10 10:53:13 +0900 |
---|---|---|
committer | Koichi Sasada <[email protected]> | 2023-10-12 14:47:01 +0900 |
commit | be1bbd5b7d40ad863ab35097765d3754726bbd54 (patch) | |
tree | 2995a0859bea1d6b2903dcd324f41869dbef14a1 /test | |
parent | 096ee0648e215915a3019c2cd68ba220d94eca12 (diff) |
M:N thread scheduler for Ractors
This patch introduce M:N thread scheduler for Ractor system.
In general, M:N thread scheduler employs N native threads (OS threads)
to manage M user-level threads (Ruby threads in this case).
On the Ruby interpreter, 1 native thread is provided for 1 Ractor
and all Ruby threads are managed by the native thread.
From Ruby 1.9, the interpreter uses 1:1 thread scheduler which means
1 Ruby thread has 1 native thread. M:N scheduler change this strategy.
Because of compatibility issue (and stableness issue of the implementation)
main Ractor doesn't use M:N scheduler on default. On the other words,
threads on the main Ractor will be managed with 1:1 thread scheduler.
There are additional settings by environment variables:
`RUBY_MN_THREADS=1` enables M:N thread scheduler on the main ractor.
Note that non-main ractors use the M:N scheduler without this
configuration. With this configuration, single ractor applications
run threads on M:1 thread scheduler (green threads, user-level threads).
`RUBY_MAX_CPU=n` specifies maximum number of native threads for
M:N scheduler (default: 8).
This patch will be reverted soon if non-easy issues are found.
[Bug #19842]
Diffstat (limited to 'test')
-rw-r--r-- | test/.excludes/TestThread.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_thread.rb | 3 |
2 files changed, 6 insertions, 1 deletions
diff --git a/test/.excludes/TestThread.rb b/test/.excludes/TestThread.rb index cf7e88427e..f26ea420a6 100644 --- a/test/.excludes/TestThread.rb +++ b/test/.excludes/TestThread.rb @@ -12,3 +12,7 @@ if /freebsd13/ =~ RUBY_PLATFORM # /usr/home/chkbuild/chkbuild/tmp/build/20220216T143001Z/ruby/test/ruby/test_thread.rb:1390:in `test_signal_at_join' exclude(:test_signal_at_join, 'gets stuck somewhere') end +if /mswin/ =~ RUBY_PLATFORM && ENV.key?('GITHUB_ACTIONS') + # to avoid "`failed to allocate memory (NoMemoryError)" error + exclude(:test_thread_interrupt_for_killed_thread, 'TODO') +end diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index bcd6590903..da14c429e6 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -1435,7 +1435,8 @@ q.pop Thread.pass until th1.stop? # After a thread starts (and execute `sleep`), it returns native_thread_id - assert_instance_of Integer, th1.native_thread_id + native_tid = th1.native_thread_id + assert_instance_of Integer, native_tid if native_tid # it can be nil th1.wakeup Thread.pass while th1.alive? |