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 /ractor_core.h | |
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 'ractor_core.h')
-rw-r--r-- | ractor_core.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/ractor_core.h b/ractor_core.h index 38aded1507..36c0e91c7a 100644 --- a/ractor_core.h +++ b/ractor_core.h @@ -103,7 +103,6 @@ struct rb_ractor_sync { #if RACTOR_CHECK_MODE > 0 VALUE locked_by; #endif - rb_nativethread_cond_t cond; bool incoming_port_closed; bool outgoing_port_closed; @@ -120,7 +119,12 @@ struct rb_ractor_sync { struct ractor_wait { enum rb_ractor_wait_status status; enum rb_ractor_wakeup_status wakeup_status; + rb_thread_t *waiting_thread; } wait; + +#ifndef RUBY_THREAD_PTHREAD_H + rb_nativethread_cond_t cond; +#endif }; // created @@ -310,11 +314,13 @@ static inline void rb_ractor_set_current_ec_(rb_ractor_t *cr, rb_execution_context_t *ec, const char *file, int line) { #ifdef RB_THREAD_LOCAL_SPECIFIER + # ifdef __APPLE__ rb_current_ec_set(ec); # else ruby_current_ec = ec; # endif + #else native_tls_set(ruby_current_ec_key, ec); #endif |