instance method
Monitor#try_enter
() -> bool
try_enter → true or false
ext/monitor/monitor.c
View on GitHub ↗
static VALUE
monitor_try_enter(VALUE monitor)
{
struct rb_monitor *mc = monitor_ptr(monitor);
VALUE current_fiber = rb_fiber_current();
if (!mc_owner_p(mc, current_fiber)) {
if (!rb_mutex_trylock(mc->mutex)) {
return Qfalse;
}
RB_OBJ_WRITE(monitor, &mc->owner, current_fiber);
mc->count = 0;
}
mc->count += 1;
return Qtrue;
}
Attempts to enter exclusive section. Returns false if lock fails.