mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
thread: remove the unused SNT_KEEP_SECONDS path
An idle shared thread that waits SNT_KEEP_SECONDS without being given a
ractor retires itself. It has been defined to 0 since be1bbd5b7d
introduced it in 2023, so it has not been compiled since, and reviving it
as written would not do much: the deadline is recomputed on every turn of
the wait loop, so a thread that keeps being woken to find the queue empty
resets it every time and never times out. It also reads the clock inside
the scheduler lock on every wait.
Its bookkeeping had drifted as well: it decrements running_cnt, which
counts the threads on vm->ractor.sched.running_threads, while a thread
waiting here holds none.
The branch after the wait loop that existed only to assert this case goes
with it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e1c3e69b6f
commit
1da2eea37c
1 file changed
-22
Notes:
git
2026-08-13 12:50:24 +00:00
@@ -1408,10 +1408,6 @@ ractor_sched_enq(rb_vm_t *vm, rb_ractor_t *r)
|
||||
}
|
||||
|
||||
|
||||
#ifndef SNT_KEEP_SECONDS
|
||||
#define SNT_KEEP_SECONDS 0
|
||||
#endif
|
||||
|
||||
#ifndef MINIMUM_SNT
|
||||
// make at least MINIMUM_SNT snts for debug.
|
||||
#define MINIMUM_SNT 0
|
||||
@@ -1433,25 +1429,11 @@ ractor_sched_deq(rb_vm_t *vm, rb_ractor_t *cr)
|
||||
while ((r = ccan_list_pop(&vm->ractor.sched.grq, rb_ractor_t, threads.sched.grq_node)) == NULL) {
|
||||
RUBY_DEBUG_LOG("wait grq_cnt:%d", (int)vm->ractor.sched.grq_cnt);
|
||||
|
||||
#if SNT_KEEP_SECONDS > 0
|
||||
rb_hrtime_t abs = rb_hrtime_add(rb_hrtime_now(), RB_HRTIME_PER_SEC * SNT_KEEP_SECONDS);
|
||||
if (native_cond_timedwait(&vm->ractor.sched.cond, &vm->ractor.sched.lock, &abs) == ETIMEDOUT) {
|
||||
RUBY_DEBUG_LOG("timeout, grq_cnt:%d", (int)vm->ractor.sched.grq_cnt);
|
||||
VM_ASSERT(r == NULL);
|
||||
vm->ractor.sched.snt_cnt--;
|
||||
vm->ractor.sched.running_cnt--;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
RUBY_DEBUG_LOG("wakeup grq_cnt:%d", (int)vm->ractor.sched.grq_cnt);
|
||||
}
|
||||
#else
|
||||
ractor_sched_set_unlocked(vm, cr);
|
||||
rb_native_cond_wait(&vm->ractor.sched.cond, &vm->ractor.sched.lock);
|
||||
ractor_sched_set_locked(vm, cr);
|
||||
|
||||
RUBY_DEBUG_LOG("wakeup grq_cnt:%d", (int)vm->ractor.sched.grq_cnt);
|
||||
#endif
|
||||
}
|
||||
|
||||
VM_ASSERT(rb_current_execution_context(false) == NULL);
|
||||
@@ -1462,10 +1444,6 @@ ractor_sched_deq(rb_vm_t *vm, rb_ractor_t *cr)
|
||||
vm->ractor.sched.grq_cnt--;
|
||||
RUBY_DEBUG_LOG("r:%d grq_cnt:%u", (int)rb_ractor_id(r), vm->ractor.sched.grq_cnt);
|
||||
}
|
||||
else {
|
||||
VM_ASSERT(SNT_KEEP_SECONDS > 0);
|
||||
// timeout
|
||||
}
|
||||
}
|
||||
ractor_sched_unlock(vm, cr);
|
||||
|
||||
|
||||
Reference in new issue
Block a user