@@ -7,7 +7,7 @@ module Concurrent
7
7
RSpec . shared_examples :attr_volatile do
8
8
9
9
specify 'older writes are always visible' do
10
- store = store ( )
10
+ store = store ( )
11
11
store . not_volatile = 0
12
12
store . volatile = 0
13
13
@@ -120,12 +120,12 @@ def ns_initialize
120
120
describe '#wait' do
121
121
122
122
it 'puts the current thread to sleep' do
123
- t = in_thread do
123
+ t1 = in_thread do
124
124
Thread . abort_on_exception = true
125
125
subject . wait
126
126
end
127
- sleep 0.1
128
- expect ( t . status ) . to eq 'sleep'
127
+ t2 = in_thread { Thread . pass until t1 . status == 'sleep' }
128
+ join_with t2 , timeout : 5
129
129
end
130
130
131
131
it 'allows the sleeping thread to be killed' do
@@ -142,29 +142,25 @@ def ns_initialize
142
142
143
143
it 'releases the lock on the current object' do
144
144
t1 = in_thread do
145
+ # #wait should release lock, even if it was already held on entry
145
146
t2 = in_thread { subject . wait }
146
- sleep 0.1
147
- # TODO (pitr-ch 15-Oct-2016): https://travis-ci.org/pitr-ch/concurrent-ruby/jobs/167933569
148
- status = t2 . status
149
- subject . synchronize { } # we will deadlock here if #wait doesn't release lock
147
+ Thread . pass until t2 . status == 'sleep'
148
+ subject . synchronize { } # it will deadlock here if #wait doesn't release lock
149
+ t2
150
150
end
151
-
152
- join_with t1
153
- expect ( t1 . value ) . to eq 'sleep'
151
+ join_with t1 , timeout : 5
152
+ expect ( t1 . value . status ) . to eq 'sleep'
154
153
end
155
154
156
155
it 'can be called from within a #synchronize block' do
157
156
t1 = in_thread do
158
- # #wait should release lock, even if it was already held on entry
159
157
t2 = in_thread { subject . synchronize { subject . wait } }
160
- sleep 0.1
161
- status = t2 . status
162
- subject . synchronize { } # we will deadlock here if lock wasn't released
163
- status
158
+ Thread . pass until t2 . status == 'sleep'
159
+ subject . synchronize { } # it will deadlock here if #wait doesn't release lock
160
+ t2
164
161
end
165
-
166
- join_with t1
167
- expect ( t1 . value ) . to eq 'sleep'
162
+ join_with t1 , timeout : 5
163
+ expect ( t1 . value . status ) . to eq 'sleep'
168
164
end
169
165
end
170
166
0 commit comments