Skip to content

Commit

Permalink
MN: ceil timeout milli seconds
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
ko1 committed Dec 22, 2023
1 parent c974ee1 commit a4b7372
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion thread_pthread.c
Expand Up @@ -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);
Expand Down

0 comments on commit a4b7372

Please sign in to comment.