File tree Expand file tree Collapse file tree 1 file changed +88
-0
lines changed
spec/ruby/library/monitor Expand file tree Collapse file tree 1 file changed +88
-0
lines changed Original file line number Diff line number Diff line change
1
+ require_relative '../../spec_helper'
2
+ require 'monitor'
3
+
4
+ describe "Monitor#new_cond" do
5
+ it "creates a MonitorMixin::ConditoinVariable" do
6
+ m = Monitor . new
7
+ c = m . new_cond
8
+ c . class . should == MonitorMixin ::ConditionVariable
9
+ end
10
+
11
+ it 'returns a condition variable which can be waited on by a thread holding the monitor' do
12
+ m = Monitor . new
13
+ c = m . new_cond
14
+
15
+ 10 . times do
16
+
17
+ locked = false
18
+ thread = Thread . new do
19
+ m . synchronize do
20
+ locked = true
21
+ c . wait
22
+ end
23
+ :done
24
+ end
25
+
26
+ Thread . pass until locked
27
+ Thread . pass until thread . stop?
28
+
29
+ m . synchronize { c . signal }
30
+
31
+ thread . join
32
+ thread . value . should == :done
33
+ end
34
+ end
35
+
36
+ it 'returns a condition variable which can be waited on by a thread holding the monitor inside multiple synchronize blocks' do
37
+ m = Monitor . new
38
+ c = m . new_cond
39
+
40
+ 10 . times do
41
+
42
+ locked = false
43
+ thread = Thread . new do
44
+ m . synchronize do
45
+ m . synchronize do
46
+ locked = true
47
+ c . wait
48
+ end
49
+ end
50
+ :done
51
+ end
52
+
53
+ Thread . pass until locked
54
+ Thread . pass until thread . stop?
55
+
56
+ m . synchronize { c . signal }
57
+
58
+ thread . join
59
+ thread . value . should == :done
60
+ end
61
+ end
62
+
63
+ it 'returns a condition variable which can be signalled by a thread holding the monitor inside multiple synchronize blocks' do
64
+ m = Monitor . new
65
+ c = m . new_cond
66
+
67
+ 10 . times do
68
+
69
+ locked = false
70
+ thread = Thread . new do
71
+ m . synchronize do
72
+ locked = true
73
+ c . wait
74
+ end
75
+ :done
76
+ end
77
+
78
+ Thread . pass until locked
79
+ Thread . pass until thread . stop?
80
+
81
+ m . synchronize { m . synchronize { c . signal } }
82
+
83
+ thread . join
84
+ thread . value . should == :done
85
+ end
86
+ end
87
+
88
+ end
You can’t perform that action at this time.
0 commit comments