12#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
16#define TIME_QUANTUM_USEC (10 * 1000)
17#define RB_CONDATTR_CLOCK_MONOTONIC 1
21#define native_thread_yield() Sleep(0)
22#define unregister_ubf_list(th)
23#define ubf_wakeup_all_threads() do {} while (0)
24#define ubf_threads_empty() (1)
25#define ubf_timer_disarm() do {} while (0)
26#define ubf_list_atfork() do {} while (0)
28static volatile DWORD ruby_native_thread_key = TLS_OUT_OF_INDEXES;
30static int w32_wait_events(HANDLE *events,
int count, DWORD timeout,
rb_thread_t *th);
32rb_internal_thread_event_hook_t *
48w32_error(const
char *func)
51 DWORD err = GetLastError();
52 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
53 FORMAT_MESSAGE_FROM_SYSTEM |
54 FORMAT_MESSAGE_IGNORE_INSERTS,
57 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
58 (LPTSTR) & lpMsgBuf, 0, NULL) == 0)
59 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
60 FORMAT_MESSAGE_FROM_SYSTEM |
61 FORMAT_MESSAGE_IGNORE_INSERTS,
64 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
65 (LPTSTR) & lpMsgBuf, 0, NULL);
66 rb_bug(
"%s: %s", func, (
char*)lpMsgBuf);
70#define W32_EVENT_DEBUG 0
73#define w32_event_debug printf
75#define w32_event_debug if (0) printf
79w32_mutex_lock(HANDLE lock,
bool try)
84 w32_event_debug(
"lock:%p\n", lock);
86 result = w32_wait_events(&lock, 1,
try ? 0 : INFINITE, 0);
90 w32_event_debug(
"locked lock:%p\n", lock);
93 case WAIT_OBJECT_0 + 1:
96 w32_event_debug(
"interrupted lock:%p\n", lock);
100 w32_event_debug(
"timeout locK:%p\n", lock);
104 rb_bug(
"win32_mutex_lock: WAIT_ABANDONED");
108 rb_bug(
"win32_mutex_lock: unknown result (%ld)", result);
116w32_mutex_create(
void)
118 HANDLE lock = CreateMutex(NULL, FALSE, NULL);
120 w32_error(
"rb_native_mutex_initialize");
130 w32_mutex_lock(sched->lock,
false);
131 if (GVL_DEBUG) fprintf(stderr,
"gvl acquire (%p): acquire\n", th);
134#define thread_sched_to_dead thread_sched_to_waiting
139 ReleaseMutex(sched->lock);
145 thread_sched_to_waiting(sched, th);
146 native_thread_yield();
147 thread_sched_to_running(sched, th);
153 if (GVL_DEBUG) fprintf(stderr,
"sched init\n");
154 sched->lock = w32_mutex_create();
162 if (GVL_DEBUG) fprintf(stderr,
"sched destroy\n");
163 CloseHandle(sched->lock);
168ruby_thread_from_native(
void)
170 return TlsGetValue(ruby_native_thread_key);
177 rb_ractor_set_current_ec(th->ractor, th->ec);
179 return TlsSetValue(ruby_native_thread_key, th);
185 if ((ruby_current_ec_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) {
186 rb_bug(
"TlsAlloc() for ruby_current_ec_key fails");
188 if ((ruby_native_thread_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) {
189 rb_bug(
"TlsAlloc() for ruby_native_thread_key fails");
194 ruby_thread_set_native(main_th);
195 main_th->nt->interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
197 DuplicateHandle(GetCurrentProcess(),
200 &main_th->nt->thread_id, 0, FALSE, DUPLICATE_SAME_ACCESS);
202 RUBY_DEBUG_LOG(
"initial thread th:%u thid:%p, event: %p",
203 rb_th_serial(main_th),
204 main_th->nt->thread_id,
205 main_th->nt->interrupt_event);
209ruby_mn_threads_params(
void)
214w32_wait_events(HANDLE *events,
int count, DWORD timeout,
rb_thread_t *th)
216 HANDLE *targets = events;
218 const int initcount = count;
221 w32_event_debug(
"events:%p, count:%d, timeout:%ld, th:%u\n",
222 events, count, timeout, th ? rb_th_serial(th) : UINT_MAX);
224 if (th && (intr = th->nt->interrupt_event)) {
225 if (ResetEvent(intr) && (!RUBY_VM_INTERRUPTED(th->ec) || SetEvent(intr))) {
226 targets =
ALLOCA_N(HANDLE, count + 1);
227 memcpy(targets, events,
sizeof(HANDLE) * count);
229 targets[count++] = intr;
230 w32_event_debug(
"handle:%p (count:%d, intr)\n", intr, count);
232 else if (intr == th->nt->interrupt_event) {
233 w32_error(
"w32_wait_events");
237 w32_event_debug(
"WaitForMultipleObjects start count:%d\n", count);
238 ret = WaitForMultipleObjects(count, targets, FALSE, timeout);
239 w32_event_debug(
"WaitForMultipleObjects end ret:%lu\n", ret);
241 if (ret == (DWORD)(WAIT_OBJECT_0 + initcount) && th) {
244 if (ret == WAIT_FAILED && W32_EVENT_DEBUG) {
247 for (i = 0; i < count; i++) {
248 w32_event_debug(
"i:%d %s\n", i, GetHandleInformation(targets[i], &dmy) ?
"OK" :
"NG");
254static void ubf_handle(
void *ptr);
255#define ubf_select ubf_handle
258rb_w32_wait_events_blocking(HANDLE *events,
int num, DWORD timeout)
260 return w32_wait_events(events, num, timeout, ruby_thread_from_native());
264rb_w32_wait_events(HANDLE *events,
int num, DWORD timeout)
269 BLOCKING_REGION(th, ret = rb_w32_wait_events_blocking(events, num, timeout),
270 ubf_handle, ruby_thread_from_native(), FALSE);
275w32_close_handle(HANDLE handle)
277 if (CloseHandle(handle) == 0) {
278 w32_error(
"w32_close_handle");
283w32_resume_thread(HANDLE handle)
285 if (ResumeThread(handle) == (DWORD)-1) {
286 w32_error(
"w32_resume_thread");
291#define HAVE__BEGINTHREADEX 1
293#undef HAVE__BEGINTHREADEX
296#ifdef HAVE__BEGINTHREADEX
297#define start_thread (HANDLE)_beginthreadex
298#define thread_errno errno
299typedef unsigned long (__stdcall *w32_thread_start_func)(
void*);
301#define start_thread CreateThread
302#define thread_errno rb_w32_map_errno(GetLastError())
303typedef LPTHREAD_START_ROUTINE w32_thread_start_func;
307w32_create_thread(DWORD stack_size, w32_thread_start_func func,
void *val)
309 return start_thread(0, stack_size, func, val, CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION, 0);
313rb_w32_sleep(
unsigned long msec)
315 return w32_wait_events(0, 0, msec, ruby_thread_from_native());
319rb_w32_Sleep(
unsigned long msec)
324 BLOCKING_REGION(th, ret = rb_w32_sleep(msec),
325 ubf_handle, ruby_thread_from_native(), FALSE);
330hrtime2msec(rb_hrtime_t hrt)
332 return (DWORD)hrt / (DWORD)RB_HRTIME_PER_MSEC;
338 const volatile DWORD msec = rel ? hrtime2msec(*rel) : INFINITE;
340 THREAD_BLOCKING_BEGIN(th);
345 th->unblock.func = ubf_handle;
346 th->unblock.arg = th;
349 if (RUBY_VM_INTERRUPTED(th->ec)) {
353 RUBY_DEBUG_LOG(
"start msec:%lu", msec);
354 ret = w32_wait_events(0, 0, msec, th);
355 RUBY_DEBUG_LOG(
"done ret:%lu", ret);
360 th->unblock.func = 0;
364 THREAD_BLOCKING_END(th);
370#ifdef USE_WIN32_MUTEX
371 w32_mutex_lock(lock->mutex,
false);
373 EnterCriticalSection(&lock->crit);
380#ifdef USE_WIN32_MUTEX
381 return w32_mutex_lock(lock->mutex,
true);
383 return TryEnterCriticalSection(&lock->crit) == 0 ? EBUSY : 0;
390#ifdef USE_WIN32_MUTEX
391 RUBY_DEBUG_LOG(
"lock:%p", lock->mutex);
392 ReleaseMutex(lock->mutex);
394 LeaveCriticalSection(&lock->crit);
401#ifdef USE_WIN32_MUTEX
402 lock->mutex = w32_mutex_create();
405 InitializeCriticalSection(&lock->crit);
412#ifdef USE_WIN32_MUTEX
413 w32_close_handle(lock->mutex);
415 DeleteCriticalSection(&lock->crit);
419struct cond_event_entry {
420 struct cond_event_entry* next;
421 struct cond_event_entry* prev;
429 struct cond_event_entry *e = cond->next;
430 struct cond_event_entry *head = (
struct cond_event_entry*)cond;
433 struct cond_event_entry *next = e->next;
434 struct cond_event_entry *prev = e->prev;
438 e->next = e->prev = e;
448 struct cond_event_entry *e = cond->next;
449 struct cond_event_entry *head = (
struct cond_event_entry*)cond;
452 struct cond_event_entry *next = e->next;
453 struct cond_event_entry *prev = e->prev;
459 e->next = e->prev = e;
466native_cond_timedwait_ms(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex,
unsigned long msec)
469 struct cond_event_entry entry;
470 struct cond_event_entry *head = (
struct cond_event_entry*)cond;
472 entry.event = CreateEvent(0, FALSE, FALSE, 0);
476 entry.prev = head->prev;
477 head->prev->next = &entry;
482 r = WaitForSingleObject(entry.event, msec);
483 if ((r != WAIT_OBJECT_0) && (r != WAIT_TIMEOUT)) {
484 rb_bug(
"rb_native_cond_wait: WaitForSingleObject returns %lu", r);
489 entry.prev->next = entry.next;
490 entry.next->prev = entry.prev;
492 w32_close_handle(entry.event);
493 return (r == WAIT_OBJECT_0) ? 0 : ETIMEDOUT;
499 native_cond_timedwait_ms(cond, mutex, INFINITE);
503abs_timespec_to_timeout_ms(
const struct timespec *ts)
508 gettimeofday(&now, NULL);
509 tv.tv_sec = ts->tv_sec;
510 tv.tv_usec = ts->tv_nsec / 1000;
512 if (!rb_w32_time_subtract(&tv, &now))
515 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
519native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex,
const struct timespec *ts)
521 unsigned long timeout_ms;
523 timeout_ms = abs_timespec_to_timeout_ms(ts);
527 return native_cond_timedwait_ms(cond, mutex, timeout_ms);
530static struct timespec native_cond_timeout(rb_nativethread_cond_t *cond,
struct timespec timeout_rel);
536 .tv_sec = msec / 1000,
537 .tv_nsec = (msec % 1000) * 1000 * 1000,
539 struct timespec ts = native_cond_timeout(cond, rel);
540 native_cond_timedwait(cond, mutex, &ts);
544native_cond_timeout(rb_nativethread_cond_t *cond,
struct timespec timeout_rel)
551 ret = gettimeofday(&tv, 0);
554 now.tv_sec = tv.tv_sec;
555 now.tv_nsec = tv.tv_usec * 1000;
557 timeout.tv_sec = now.tv_sec;
558 timeout.tv_nsec = now.tv_nsec;
559 timeout.tv_sec += timeout_rel.tv_sec;
560 timeout.tv_nsec += timeout_rel.tv_nsec;
562 if (timeout.tv_nsec >= 1000*1000*1000) {
564 timeout.tv_nsec -= 1000*1000*1000;
567 if (timeout.tv_sec < now.tv_sec)
568 timeout.tv_sec = TIMET_MAX;
576 cond->next = (
struct cond_event_entry *)cond;
577 cond->prev = (
struct cond_event_entry *)cond;
591#define CHECK_ERR(expr) \
592 {if (!(expr)) {rb_bug("err: %lu - %s", GetLastError(), #expr);}}
596COMPILER_WARNING_IGNORED(-Wmaybe-uninitialized)
599query_memory_basic_info(PMEMORY_BASIC_INFORMATION mi)
601 return VirtualQuery(mi, mi,
sizeof(*mi));
608 MEMORY_BASIC_INFORMATION mi;
612 CHECK_ERR(query_memory_basic_info(&mi));
613 base = mi.AllocationBase;
614 end = mi.BaseAddress;
615 end += mi.RegionSize;
618 if (space > 1024*1024) space = 1024*1024;
619 th->ec->machine.stack_start = (
VALUE *)end - 1;
620 th->ec->machine.stack_maxsize = size - space;
623#ifndef InterlockedExchangePointer
624#define InterlockedExchangePointer(t, v) \
625 (void *)InterlockedExchange((long *)(t), (long)(v))
631 HANDLE intr = InterlockedExchangePointer(&nt->interrupt_event, 0);
632 RUBY_DEBUG_LOG(
"close handle intr:%p, thid:%p\n", intr, nt->thread_id);
633 w32_close_handle(intr);
637static unsigned long __stdcall
638thread_start_func_1(
void *th_ptr)
641 volatile HANDLE thread_id = th->nt->thread_id;
643 native_thread_init_stack(th);
644 th->nt->interrupt_event = CreateEvent(0, TRUE, FALSE, 0);
647 RUBY_DEBUG_LOG(
"thread created th:%u, thid: %p, event: %p",
648 rb_th_serial(th), th->nt->thread_id, th->nt->interrupt_event);
650 thread_sched_to_running(TH_SCHED(th), th);
651 ruby_thread_set_native(th);
654 thread_start_func_2(th, th->ec->machine.stack_start);
656 w32_close_handle(thread_id);
657 RUBY_DEBUG_LOG(
"thread deleted th:%u", rb_th_serial(th));
666 const size_t stack_size = th->vm->default_params.thread_machine_stack_size;
668 th->nt->thread_id = w32_create_thread(stack_size, thread_start_func_1, th);
671 size_t vm_stack_word_size = th->vm->default_params.thread_vm_stack_size /
sizeof(
VALUE);
672 void *vm_stack = ruby_xmalloc(vm_stack_word_size *
sizeof(
VALUE));
673 th->sched.vm_stack = vm_stack;
674 rb_ec_initialize_vm_stack(th->ec, vm_stack, vm_stack_word_size);
676 if ((th->nt->thread_id) == 0) {
680 w32_resume_thread(th->nt->thread_id);
682 if (USE_RUBY_DEBUG_LOG) {
684 RUBY_DEBUG_LOG(
"th:%u thid:%p intr:%p), stack size: %"PRIuSIZE
"",
685 rb_th_serial(th), th->nt->thread_id,
686 th->nt->interrupt_event, stack_size);
692native_thread_join(HANDLE th)
694 w32_wait_events(&th, 1, INFINITE, 0);
697#if USE_NATIVE_THREAD_PRIORITY
702 int priority = th->priority;
703 if (th->priority > 0) {
704 priority = THREAD_PRIORITY_ABOVE_NORMAL;
706 else if (th->priority < 0) {
707 priority = THREAD_PRIORITY_BELOW_NORMAL;
710 priority = THREAD_PRIORITY_NORMAL;
713 SetThreadPriority(th->nt->thread_id, priority);
718int rb_w32_select_with_thread(
int, fd_set *, fd_set *, fd_set *,
struct timeval *,
void *);
723 fd_set *r = NULL, *w = NULL, *e = NULL;
736 return rb_w32_select_with_thread(n, r, w, e, timeout, th);
743 return w32_wait_events(0, 0, 0, th);
750 RUBY_DEBUG_LOG(
"th:%u\n", rb_th_serial(th));
752 if (!SetEvent(th->nt->interrupt_event)) {
753 w32_error(
"ubf_handle");
757int rb_w32_set_thread_description(HANDLE th,
const WCHAR *name);
758int rb_w32_set_thread_description_str(HANDLE th,
VALUE name);
759#define native_set_another_thread_name rb_w32_set_thread_description_str
765#define TIMER_THREAD_CREATED_P() (timer_thread.id != 0)
767static unsigned long __stdcall
768timer_thread_func(
void *dummy)
771 RUBY_DEBUG_LOG(
"start");
772 rb_w32_set_thread_description(GetCurrentThread(), L
"ruby-timer-thread");
773 while (WaitForSingleObject(timer_thread.lock,
774 TIME_QUANTUM_USEC/1000) == WAIT_TIMEOUT) {
776 rb_threadptr_check_signal(vm->ractor.main_thread);
778 RUBY_DEBUG_LOG(
"end");
783rb_thread_wakeup_timer_thread(
int sig)
789rb_thread_create_timer_thread(
void)
791 if (timer_thread.id == 0) {
792 if (!timer_thread.lock) {
793 timer_thread.lock = CreateEvent(0, TRUE, FALSE, 0);
795 timer_thread.id = w32_create_thread(1024 + (USE_RUBY_DEBUG_LOG ? BUFSIZ : 0),
796 timer_thread_func, 0);
797 w32_resume_thread(timer_thread.id);
802native_stop_timer_thread(
void)
804 int stopped = --system_working <= 0;
806 SetEvent(timer_thread.lock);
807 native_thread_join(timer_thread.id);
808 CloseHandle(timer_thread.lock);
809 timer_thread.lock = 0;
815native_reset_timer_thread(
void)
817 if (timer_thread.id) {
818 CloseHandle(timer_thread.id);
824ruby_stack_overflowed_p(
const rb_thread_t *th,
const void *addr)
826 return rb_ec_raised_p(th->ec, RAISED_STACKOVERFLOW);
829#if defined(__MINGW32__)
831rb_w32_stack_overflow_handler(
struct _EXCEPTION_POINTERS *exception)
833 if (exception->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
834 rb_ec_raised_set(GET_EC(), RAISED_STACKOVERFLOW);
837 return EXCEPTION_CONTINUE_SEARCH;
841#ifdef RUBY_ALLOCA_CHKSTK
843ruby_alloca_chkstk(
size_t len,
void *sp)
847 if (!rb_ec_raised_p(ec, RAISED_STACKOVERFLOW)) {
848 rb_ec_raised_set(ec, RAISED_STACKOVERFLOW);
849 rb_exc_raise(sysstack_error);
863 return GetCurrentThread();
874 DWORD tid = GetThreadId(th->nt->thread_id);
875 if (tid == 0) rb_sys_fail(
"GetThreadId");
878#define USE_NATIVE_THREAD_NATIVE_THREAD_ID 1
900 native_thread_destroy(th->nt);
902 ruby_xfree(th->sched.vm_stack);
912rb_thread_sched_mark_zombies(
rb_vm_t *vm)
918vm_barrier_finish_p(
rb_vm_t *vm)
920 RUBY_DEBUG_LOG(
"cnt:%u living:%u blocking:%u",
921 vm->ractor.blocking_cnt == vm->ractor.cnt,
922 vm->ractor.sync.barrier_cnt,
924 vm->ractor.blocking_cnt);
926 VM_ASSERT(vm->ractor.blocking_cnt <= vm->ractor.cnt);
927 return vm->ractor.blocking_cnt == vm->ractor.cnt;
933 vm->ractor.sync.barrier_waiting =
true;
935 RUBY_DEBUG_LOG(
"barrier start. cnt:%u living:%u blocking:%u",
936 vm->ractor.sync.barrier_cnt,
938 vm->ractor.blocking_cnt);
940 rb_vm_ractor_blocking_cnt_inc(vm, cr, __FILE__, __LINE__);
944 ccan_list_for_each(&vm->ractor.set, r, vmlr_node) {
946 rb_ractor_vm_barrier_interrupt_running_thread(r);
951 while (!vm_barrier_finish_p(vm)) {
952 rb_vm_cond_wait(vm, &vm->ractor.sync.barrier_cond);
955 RUBY_DEBUG_LOG(
"cnt:%u barrier success", vm->ractor.sync.barrier_cnt);
957 rb_vm_ractor_blocking_cnt_dec(vm, cr, __FILE__, __LINE__);
959 vm->ractor.sync.barrier_waiting =
false;
960 vm->ractor.sync.barrier_cnt++;
962 ccan_list_for_each(&vm->ractor.set, r, vmlr_node) {
970 vm->ractor.sync.lock_owner = cr;
971 unsigned int barrier_cnt = vm->ractor.sync.barrier_cnt;
975 RB_VM_SAVE_MACHINE_CONTEXT(th);
977 if (rb_ractor_status_p(cr, ractor_running)) {
978 rb_vm_ractor_blocking_cnt_inc(vm, cr, __FILE__, __LINE__);
984 VM_ASSERT(rb_ractor_status_p(cr, ractor_blocking));
986 if (vm_barrier_finish_p(vm)) {
987 RUBY_DEBUG_LOG(
"wakeup barrier owner");
991 RUBY_DEBUG_LOG(
"wait for barrier finish");
995 while (barrier_cnt == vm->ractor.sync.barrier_cnt) {
996 vm->ractor.sync.lock_owner = NULL;
998 VM_ASSERT(vm->ractor.sync.lock_owner == NULL);
999 vm->ractor.sync.lock_owner = cr;
1002 RUBY_DEBUG_LOG(
"barrier is released. Acquire vm_lock");
1005 rb_vm_ractor_blocking_cnt_dec(vm, cr, __FILE__, __LINE__);
1008 vm->ractor.sync.lock_owner = NULL;
uint32_t rb_event_flag_t
Represents event(s).
#define UNREACHABLE
Old name of RBIMPL_UNREACHABLE.
#define ULONG2NUM
Old name of RB_ULONG2NUM.
#define ZALLOC
Old name of RB_ZALLOC.
void ruby_init_stack(volatile VALUE *addr)
Set stack bottom of Ruby implementation.
size_t ruby_stack_length(VALUE **p)
Queries what Ruby thinks is the machine stack.
int rb_reserved_fd_p(int fd)
Queries if the given FD is reserved or not.
int len
Length of the buffer.
rb_internal_thread_event_hook_t * rb_internal_thread_add_event_hook(rb_internal_thread_event_callback func, rb_event_flag_t events, void *data)
Registers a thread event hook function.
bool rb_internal_thread_remove_event_hook(rb_internal_thread_event_hook_t *hook)
Unregister the passed hook.
static fd_set * rb_fd_ptr(const rb_fdset_t *f)
Raw pointer to fd_set.
#define ALLOCA_N(type, n)
#define RBIMPL_ATTR_NORETURN()
Wraps (or simulates) [[noreturn]]
#define errno
Ractor-aware version of errno.
#define rb_fd_resize(n, f)
Does nothing (defined for compatibility).
The data structure which wraps the fd_set bitmap used by select(2).
rb_nativethread_id_t rb_nativethread_self(void)
Queries the ID of the native thread that is calling this function.
void rb_native_mutex_lock(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_lock.
void rb_native_cond_initialize(rb_nativethread_cond_t *cond)
Fills the passed condition variable with an initial value.
int rb_native_mutex_trylock(rb_nativethread_lock_t *lock)
Identical to rb_native_mutex_lock(), except it doesn't block in case rb_native_mutex_lock() would.
void rb_native_cond_broadcast(rb_nativethread_cond_t *cond)
Signals a condition variable.
void rb_native_mutex_initialize(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_initialize.
void rb_native_mutex_unlock(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_unlock.
void rb_native_mutex_destroy(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_destroy.
void rb_native_cond_destroy(rb_nativethread_cond_t *cond)
Destroys the passed condition variable.
void rb_native_cond_signal(rb_nativethread_cond_t *cond)
Signals a condition variable.
void rb_native_cond_wait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex)
Waits for the passed condition variable to be signalled.
void rb_native_cond_timedwait(rb_nativethread_cond_t *cond, rb_nativethread_lock_t *mutex, unsigned long msec)
Identical to rb_native_cond_wait(), except it additionally takes timeout in msec resolution.
uintptr_t VALUE
Type that represents a Ruby object.