Fix Thread#join(timeout)
when running inside the fiber scheduler. (#7903)
This commit is contained in:
parent
a4d92475f6
commit
0402193723
Notes:
git
2023-06-03 03:42:01 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
@ -20,6 +20,28 @@ class TestFiberThread < Test::Unit::TestCase
|
|||||||
assert_equal :done, thread.value
|
assert_equal :done, thread.value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_thread_join_timeout
|
||||||
|
sleeper = nil
|
||||||
|
|
||||||
|
thread = Thread.new do
|
||||||
|
scheduler = Scheduler.new
|
||||||
|
Fiber.set_scheduler scheduler
|
||||||
|
|
||||||
|
Fiber.schedule do
|
||||||
|
sleeper = Thread.new{sleep}
|
||||||
|
sleeper.join(0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
scheduler.run
|
||||||
|
end
|
||||||
|
|
||||||
|
thread.join
|
||||||
|
|
||||||
|
assert_predicate sleeper, :alive?
|
||||||
|
ensure
|
||||||
|
sleeper&.kill
|
||||||
|
end
|
||||||
|
|
||||||
def test_thread_join_implicit
|
def test_thread_join_implicit
|
||||||
sleeping = false
|
sleeping = false
|
||||||
finished = false
|
finished = false
|
||||||
|
5
thread.c
5
thread.c
@ -1053,6 +1053,10 @@ thread_join_sleep(VALUE arg)
|
|||||||
|
|
||||||
if (scheduler != Qnil) {
|
if (scheduler != Qnil) {
|
||||||
rb_fiber_scheduler_block(scheduler, target_th->self, p->timeout);
|
rb_fiber_scheduler_block(scheduler, target_th->self, p->timeout);
|
||||||
|
// Check if the target thread is finished after blocking:
|
||||||
|
if (thread_finished(target_th)) break;
|
||||||
|
// Otherwise, a timeout occurred:
|
||||||
|
else return Qfalse;
|
||||||
}
|
}
|
||||||
else if (!limit) {
|
else if (!limit) {
|
||||||
sleep_forever(th, SLEEP_DEADLOCKABLE | SLEEP_ALLOW_SPURIOUS | SLEEP_NO_CHECKINTS);
|
sleep_forever(th, SLEEP_DEADLOCKABLE | SLEEP_ALLOW_SPURIOUS | SLEEP_NO_CHECKINTS);
|
||||||
@ -1070,6 +1074,7 @@ thread_join_sleep(VALUE arg)
|
|||||||
|
|
||||||
RUBY_DEBUG_LOG("interrupted target_th:%u status:%s", rb_th_serial(target_th), thread_status_name(target_th, TRUE));
|
RUBY_DEBUG_LOG("interrupted target_th:%u status:%s", rb_th_serial(target_th), thread_status_name(target_th, TRUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Qtrue;
|
return Qtrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user