summaryrefslogtreecommitdiff
path: root/thread_pthread.c
diff options
context:
space:
mode:
authorKoichi Sasada <ko1@atdot.net>2023-12-23 05:23:53 +0900
committerKoichi Sasada <ko1@atdot.net>2023-12-23 05:56:02 +0900
commita4b737213eb1d8f352f1f148c27e96a3f09f5d08 (patch)
tree0d09da7bdedf7e22186039b07427a92fe362623a /thread_pthread.c
parentc974ee1abe5df5a4bb97264e608afbd134c77652 (diff)
MN: ceil timeout milli seconds
`hrrel / RB_HRTIME_PER_MSEC` floor the timeout value and it can return wrong value by `Mutex#sleep` (return Integer even if it should return nil (timeout'ed)). This patch ceil the value and the issue was solved.
Diffstat (limited to 'thread_pthread.c')
-rw-r--r--thread_pthread.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/thread_pthread.c b/thread_pthread.c
index d8ca403be6..81a90d194e 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -2872,7 +2872,7 @@ timer_thread_set_timeout(rb_vm_t *vm)
RUBY_DEBUG_LOG("th:%u now:%lu rel:%lu", rb_th_serial(th), (unsigned long)now, (unsigned long)hrrel);
// TODO: overflow?
- timeout = (int)(hrrel / RB_HRTIME_PER_MSEC); // ms
+ timeout = (int)((hrrel + RB_HRTIME_PER_MSEC - 1) / RB_HRTIME_PER_MSEC); // ms
}
}
rb_native_mutex_unlock(&timer_th.waiting_lock);