summaryrefslogtreecommitdiff
path: root/spec/ruby/core/mutex/synchronize_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/mutex/synchronize_spec.rb')
-rw-r--r--spec/ruby/core/mutex/synchronize_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/ruby/core/mutex/synchronize_spec.rb b/spec/ruby/core/mutex/synchronize_spec.rb
index 206b14e828..e3dad508b8 100644
--- a/spec/ruby/core/mutex/synchronize_spec.rb
+++ b/spec/ruby/core/mutex/synchronize_spec.rb
@@ -24,4 +24,43 @@ describe "Mutex#synchronize" do
th.join
m1.locked?.should be_false
end
+
+ it "blocks the caller if already locked" do
+ m = Mutex.new
+ m.lock
+ lambda { m.synchronize { } }.should block_caller
+ end
+
+ it "does not block the caller if not locked" do
+ m = Mutex.new
+ lambda { m.synchronize { } }.should_not block_caller
+ end
+
+ it "blocks the caller if another thread is also in the synchronize block" do
+ m = Mutex.new
+ q1 = Queue.new
+ q2 = Queue.new
+
+ t = Thread.new {
+ m.synchronize {
+ q1.push :ready
+ q2.pop
+ }
+ }
+
+ q1.pop.should == :ready
+
+ lambda { m.synchronize { } }.should block_caller
+
+ q2.push :done
+ t.join
+ end
+
+ it "is not recursive" do
+ m = Mutex.new
+
+ m.synchronize do
+ lambda { m.synchronize { } }.should raise_error(ThreadError)
+ end
+ end
end