1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-12-27 16:46:08 +01:00
parent 26a9f80c82
commit a2fac1d72c
44 changed files with 772 additions and 514 deletions

View file

@ -32,6 +32,50 @@ describe "ConditionVariable#wait" do
th.join
end
it "can be interrupted by Thread#run" do
m = Mutex.new
cv = ConditionVariable.new
in_synchronize = false
th = Thread.new do
m.synchronize do
in_synchronize = true
cv.wait(m)
end
:success
end
# wait for m to acquire the mutex
Thread.pass until in_synchronize
# wait until th is sleeping (ie waiting)
Thread.pass while th.status and th.status != "sleep"
th.run
th.value.should == :success
end
it "can be interrupted by Thread#wakeup" do
m = Mutex.new
cv = ConditionVariable.new
in_synchronize = false
th = Thread.new do
m.synchronize do
in_synchronize = true
cv.wait(m)
end
:success
end
# wait for m to acquire the mutex
Thread.pass until in_synchronize
# wait until th is sleeping (ie waiting)
Thread.pass while th.status and th.status != "sleep"
th.wakeup
th.value.should == :success
end
it "reacquires the lock even if the thread is killed" do
m = Mutex.new
cv = ConditionVariable.new