Skip to content

Commit

Permalink
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion spec/ruby/library/conditionvariable/broadcast_spec.rb
Original file line number Diff line number Diff line change
@@ -10,13 +10,18 @@
it "returns self if something is waiting for a broadcast" do
m = Mutex.new
cv = ConditionVariable.new
in_synchronize = false

th = Thread.new do
m.synchronize do
in_synchronize = true
cv.wait(m)
end
end

# ensures that th grabs m before current thread
# 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"

m.synchronize { cv.broadcast }.should == cv
6 changes: 5 additions & 1 deletion spec/ruby/library/conditionvariable/wait_spec.rb
Original file line number Diff line number Diff line change
@@ -5,14 +5,18 @@
it "returns self" do
m = Mutex.new
cv = ConditionVariable.new
in_synchronize = false

th = Thread.new do
m.synchronize do
in_synchronize = true
cv.wait(m).should == cv
end
end

# ensures that th grabs m before current thread
# 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"

m.synchronize { cv.signal }

0 comments on commit 8c884c0

Please sign in to comment.