summaryrefslogtreecommitdiff
path: root/spec/ruby/library/conditionvariable/wait_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2019-12-27 16:46:08 +0100
committerBenoit Daloze <[email protected]>2019-12-27 16:46:08 +0100
commita2fac1d72c225192018f8f3f3dfcfcc46f66c08a (patch)
treedc2d44079962ce242d971a4d1c2a2b1333e64cec /spec/ruby/library/conditionvariable/wait_spec.rb
parent26a9f80c823a9f536a235d80d600aa9e03ed7a2f (diff)
Update to ruby/spec@d419e74
Diffstat (limited to 'spec/ruby/library/conditionvariable/wait_spec.rb')
-rw-r--r--spec/ruby/library/conditionvariable/wait_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/ruby/library/conditionvariable/wait_spec.rb b/spec/ruby/library/conditionvariable/wait_spec.rb
index f57ab4c778..59d708d7e6 100644
--- a/spec/ruby/library/conditionvariable/wait_spec.rb
+++ b/spec/ruby/library/conditionvariable/wait_spec.rb
@@ -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