diff options
author | Koichi Sasada <ko1@atdot.net> | 2020-03-10 02:22:11 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2020-09-03 21:11:06 +0900 |
commit | 79df14c04b452411b9d17e26a398e491bca1a811 (patch) | |
tree | 7598cee0f105439efd5bb328a727b0fe27d7c666 /thread_sync.c | |
parent | eeb5325d3bfd71301896360c17e8f51abcb9a7e5 (diff) |
Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.
[Feature #17100]
This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.
I hope this feature can help programmers from thread-safety issues.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3365
Diffstat (limited to 'thread_sync.c')
-rw-r--r-- | thread_sync.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/thread_sync.c b/thread_sync.c index 3b8c5364a9..deb3858c31 100644 --- a/thread_sync.c +++ b/thread_sync.c @@ -264,13 +264,13 @@ do_mutex_lock(VALUE self, int interruptible_p) th->status = THREAD_STOPPED_FOREVER; th->locking_mutex = self; - th->vm->sleeper++; + rb_ractor_sleeper_threads_inc(th->ractor); /* * Carefully! while some contended threads are in native_sleep(), - * vm->sleeper is unstable value. we have to avoid both deadlock + * ractor->sleeper is unstable value. we have to avoid both deadlock * and busy loop. */ - if ((vm_living_thread_num(th->vm) == th->vm->sleeper) && + if ((rb_ractor_living_thread_num(th->ractor) == rb_ractor_sleeper_thread_num(th->ractor)) && !patrol_thread) { timeout = &rel; patrol_thread = th; @@ -289,17 +289,18 @@ do_mutex_lock(VALUE self, int interruptible_p) th->locking_mutex = Qfalse; if (mutex->th && timeout && !RUBY_VM_INTERRUPTED(th->ec)) { - rb_check_deadlock(th->vm); + rb_check_deadlock(th->ractor); } if (th->status == THREAD_STOPPED_FOREVER) { th->status = prev_status; } - th->vm->sleeper--; + rb_ractor_sleeper_threads_dec(th->ractor); if (interruptible_p) { /* release mutex before checking for interrupts...as interrupt checking * code might call rb_raise() */ if (mutex->th == th) mutex->th = 0; + RUBY_VM_CHECK_INTS_BLOCKING(th->ec); /* may release mutex */ if (!mutex->th) { mutex->th = th; |