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]
22 lines
595 B
C
22 lines
595 B
C
#ifndef RUBY_THREAD_NONE_H
|
|
#define RUBY_THREAD_NONE_H
|
|
|
|
#define RB_NATIVETHREAD_LOCK_INIT (void)(0)
|
|
#define RB_NATIVETHREAD_COND_INIT (void)(0)
|
|
|
|
// no-thread impl doesn't use TLS but define this to avoid using tls key
|
|
// based implementation in vm.c
|
|
#define RB_THREAD_LOCAL_SPECIFIER
|
|
|
|
struct rb_native_thread {
|
|
void *thread_id; // NULL
|
|
};
|
|
|
|
struct rb_thread_sched_item {};
|
|
struct rb_thread_sched {};
|
|
|
|
RUBY_EXTERN struct rb_execution_context_struct *ruby_current_ec;
|
|
NOINLINE(struct rb_execution_context_struct *rb_current_ec_noinline(void)); // for assertions
|
|
|
|
#endif /* RUBY_THREAD_NONE_H */
|