concurrent-ruby 0.6.0 → 0.7.0.rc0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +55 -51
  3. data/lib/concurrent/actress/ad_hoc.rb +6 -0
  4. data/lib/concurrent/actress/context.rb +10 -8
  5. data/lib/concurrent/actress/core.rb +44 -20
  6. data/lib/concurrent/actress/core_delegations.rb +5 -0
  7. data/lib/concurrent/actress/envelope.rb +21 -5
  8. data/lib/concurrent/actress/reference.rb +5 -5
  9. data/lib/concurrent/actress.rb +152 -6
  10. data/lib/concurrent/agent.rb +9 -9
  11. data/lib/concurrent/atomic.rb +46 -0
  12. data/lib/concurrent/atomic_reference/concurrent_update_error.rb +7 -0
  13. data/lib/concurrent/atomic_reference/delegated_update.rb +28 -0
  14. data/lib/concurrent/atomic_reference/direct_update.rb +28 -0
  15. data/lib/concurrent/atomic_reference/jruby.rb +8 -0
  16. data/lib/concurrent/atomic_reference/mutex_atomic.rb +47 -0
  17. data/lib/concurrent/atomic_reference/numeric_cas_wrapper.rb +24 -0
  18. data/lib/concurrent/atomic_reference/rbx.rb +16 -0
  19. data/lib/concurrent/atomic_reference/ruby.rb +16 -0
  20. data/lib/concurrent/atomics.rb +1 -1
  21. data/lib/concurrent/configuration.rb +7 -2
  22. data/lib/concurrent/executor/ruby_thread_pool_executor.rb +0 -1
  23. data/lib/concurrent/executor/{one_by_one.rb → serialized_execution.rb} +21 -8
  24. data/lib/concurrent/executor/timer_set.rb +6 -1
  25. data/lib/concurrent/executors.rb +1 -1
  26. data/lib/concurrent/logging.rb +1 -1
  27. data/lib/concurrent/observable.rb +1 -1
  28. data/lib/concurrent/supervisor.rb +1 -1
  29. data/lib/concurrent/timer_task.rb +0 -36
  30. data/lib/concurrent/version.rb +1 -1
  31. data/lib/concurrent.rb +3 -4
  32. data/lib/concurrent_ruby_ext.so +0 -0
  33. data/lib/extension_helper.rb +9 -0
  34. metadata +19 -152
  35. data/lib/concurrent/actor/actor.rb +0 -270
  36. data/lib/concurrent/actor/postable.rb +0 -102
  37. data/lib/concurrent/actors.rb +0 -2
  38. data/lib/concurrent/actress/doc.md +0 -53
  39. data/lib/concurrent/atomic/atomic.rb +0 -48
  40. data/lib/concurrent/runnable.rb +0 -90
  41. data/lib/concurrent/stoppable.rb +0 -20
  42. data/spec/concurrent/actor/actor_spec.rb +0 -376
  43. data/spec/concurrent/actor/postable_shared.rb +0 -218
  44. data/spec/concurrent/actress_spec.rb +0 -191
  45. data/spec/concurrent/agent_spec.rb +0 -500
  46. data/spec/concurrent/async_spec.rb +0 -352
  47. data/spec/concurrent/atomic/atomic_boolean_spec.rb +0 -172
  48. data/spec/concurrent/atomic/atomic_fixnum_spec.rb +0 -186
  49. data/spec/concurrent/atomic/atomic_spec.rb +0 -133
  50. data/spec/concurrent/atomic/condition_spec.rb +0 -171
  51. data/spec/concurrent/atomic/copy_on_notify_observer_set_spec.rb +0 -10
  52. data/spec/concurrent/atomic/copy_on_write_observer_set_spec.rb +0 -10
  53. data/spec/concurrent/atomic/count_down_latch_spec.rb +0 -151
  54. data/spec/concurrent/atomic/cyclic_barrier_spec.rb +0 -248
  55. data/spec/concurrent/atomic/event_spec.rb +0 -200
  56. data/spec/concurrent/atomic/observer_set_shared.rb +0 -242
  57. data/spec/concurrent/atomic/thread_local_var_spec.rb +0 -113
  58. data/spec/concurrent/channel/buffered_channel_spec.rb +0 -151
  59. data/spec/concurrent/channel/channel_spec.rb +0 -39
  60. data/spec/concurrent/channel/probe_spec.rb +0 -77
  61. data/spec/concurrent/channel/unbuffered_channel_spec.rb +0 -132
  62. data/spec/concurrent/collection/blocking_ring_buffer_spec.rb +0 -149
  63. data/spec/concurrent/collection/priority_queue_spec.rb +0 -317
  64. data/spec/concurrent/collection/ring_buffer_spec.rb +0 -126
  65. data/spec/concurrent/configuration_spec.rb +0 -71
  66. data/spec/concurrent/dataflow_spec.rb +0 -242
  67. data/spec/concurrent/delay_spec.rb +0 -91
  68. data/spec/concurrent/dereferenceable_shared.rb +0 -146
  69. data/spec/concurrent/exchanger_spec.rb +0 -66
  70. data/spec/concurrent/executor/cached_thread_pool_shared.rb +0 -115
  71. data/spec/concurrent/executor/fixed_thread_pool_shared.rb +0 -136
  72. data/spec/concurrent/executor/global_thread_pool_shared.rb +0 -35
  73. data/spec/concurrent/executor/immediate_executor_spec.rb +0 -12
  74. data/spec/concurrent/executor/java_cached_thread_pool_spec.rb +0 -44
  75. data/spec/concurrent/executor/java_fixed_thread_pool_spec.rb +0 -64
  76. data/spec/concurrent/executor/java_single_thread_executor_spec.rb +0 -21
  77. data/spec/concurrent/executor/java_thread_pool_executor_spec.rb +0 -71
  78. data/spec/concurrent/executor/per_thread_executor_spec.rb +0 -57
  79. data/spec/concurrent/executor/ruby_cached_thread_pool_spec.rb +0 -69
  80. data/spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb +0 -39
  81. data/spec/concurrent/executor/ruby_single_thread_executor_spec.rb +0 -18
  82. data/spec/concurrent/executor/ruby_thread_pool_executor_spec.rb +0 -171
  83. data/spec/concurrent/executor/safe_task_executor_spec.rb +0 -103
  84. data/spec/concurrent/executor/thread_pool_class_cast_spec.rb +0 -52
  85. data/spec/concurrent/executor/thread_pool_executor_shared.rb +0 -155
  86. data/spec/concurrent/executor/thread_pool_shared.rb +0 -239
  87. data/spec/concurrent/executor/timer_set_spec.rb +0 -183
  88. data/spec/concurrent/future_spec.rb +0 -329
  89. data/spec/concurrent/ivar_spec.rb +0 -215
  90. data/spec/concurrent/mvar_spec.rb +0 -380
  91. data/spec/concurrent/obligation_shared.rb +0 -102
  92. data/spec/concurrent/obligation_spec.rb +0 -282
  93. data/spec/concurrent/observable_shared.rb +0 -177
  94. data/spec/concurrent/observable_spec.rb +0 -56
  95. data/spec/concurrent/options_parser_spec.rb +0 -71
  96. data/spec/concurrent/promise_spec.rb +0 -367
  97. data/spec/concurrent/runnable_shared.rb +0 -68
  98. data/spec/concurrent/runnable_spec.rb +0 -235
  99. data/spec/concurrent/scheduled_task_spec.rb +0 -342
  100. data/spec/concurrent/stoppable_shared.rb +0 -37
  101. data/spec/concurrent/supervisor_spec.rb +0 -1148
  102. data/spec/concurrent/timer_task_spec.rb +0 -258
  103. data/spec/concurrent/tvar_spec.rb +0 -137
  104. data/spec/concurrent/utility/processor_count_spec.rb +0 -20
  105. data/spec/concurrent/utility/timeout_spec.rb +0 -50
  106. data/spec/concurrent/utility/timer_spec.rb +0 -52
  107. data/spec/spec_helper.rb +0 -31
  108. data/spec/support/example_group_extensions.rb +0 -48
  109. data/spec/support/less_than_or_equal_to_matcher.rb +0 -5
  110. /data/{LICENSE → LICENSE.txt} +0 -0
@@ -1,380 +0,0 @@
1
- require 'spec_helper'
2
- require_relative 'dereferenceable_shared'
3
-
4
- module Concurrent
5
-
6
- describe MVar do
7
-
8
- context 'behavior' do
9
-
10
- # dereferenceable
11
-
12
- def dereferenceable_subject(value, opts = {})
13
- MVar.new(value, opts)
14
- end
15
-
16
- it_should_behave_like :dereferenceable
17
- end
18
-
19
- describe '#initialize' do
20
-
21
- it 'accepts no initial value' do
22
- m = MVar.new
23
- m.should be_empty
24
- end
25
-
26
- it 'accepts an empty initial value' do
27
- m = MVar.new(MVar::EMPTY)
28
- m.should be_empty
29
- end
30
-
31
- it 'accepts an initial value' do
32
- m = MVar.new(14)
33
- m.should_not be_empty
34
- end
35
-
36
- it 'accepts a nil initial value' do
37
- m = MVar.new(nil)
38
- m.should_not be_empty
39
- end
40
-
41
- end
42
-
43
- describe '#take' do
44
-
45
- it 'sets the MVar to empty' do
46
- m = MVar.new(14)
47
- m.take
48
- m.should be_empty
49
- end
50
-
51
- it 'returns the value on a full MVar' do
52
- m = MVar.new(14)
53
- m.take.should eq 14
54
- end
55
-
56
- it 'waits for another thread to #put' do
57
- m = MVar.new
58
-
59
- putter = Thread.new {
60
- sleep(0.1)
61
- m.put 14
62
- }
63
-
64
- m.take.should eq 14
65
- end
66
-
67
- it 'returns TIMEOUT on timeout on an empty MVar' do
68
- m = MVar.new
69
- m.take(0.1).should eq MVar::TIMEOUT
70
- end
71
-
72
- end
73
-
74
- describe '#put' do
75
-
76
- it 'sets the MVar to be empty' do
77
- m = MVar.new(14)
78
- m.take
79
- m.should be_empty
80
- end
81
-
82
- it 'sets a new value on an empty MVar' do
83
- m = MVar.new
84
- m.put 14
85
- m.take.should eq 14
86
- end
87
-
88
- it 'waits for another thread to #take' do
89
- m = MVar.new(14)
90
-
91
- putter = Thread.new {
92
- sleep(0.1)
93
- m.take
94
- }
95
-
96
- m.put(14).should eq 14
97
- end
98
-
99
- it 'returns TIMEOUT on timeout on a full MVar' do
100
- m = MVar.new(14)
101
- m.put(14, 0.1).should eq MVar::TIMEOUT
102
- end
103
-
104
- it 'returns the value' do
105
- m = MVar.new
106
- m.put(14).should eq 14
107
- end
108
-
109
- end
110
-
111
- describe '#empty?' do
112
-
113
- it 'returns true on an empty MVar' do
114
- m = MVar.new
115
- m.should be_empty
116
- end
117
-
118
- it 'returns false on a full MVar' do
119
- m = MVar.new(14)
120
- m.should_not be_empty
121
- end
122
-
123
- end
124
-
125
- describe '#full?' do
126
-
127
- it 'returns false on an empty MVar' do
128
- m = MVar.new
129
- m.should_not be_full
130
- end
131
-
132
- it 'returns true on a full MVar' do
133
- m = MVar.new(14)
134
- m.should be_full
135
- end
136
-
137
- end
138
-
139
- describe '#modify' do
140
-
141
- it 'raises an exception when no block given' do
142
- m = MVar.new(14)
143
- expect { m.modify }.to raise_error(ArgumentError)
144
- end
145
-
146
- it 'modifies a full MVar' do
147
- m = MVar.new(14)
148
- m.modify{ |v| v + 2 }
149
- m.take.should eq 16
150
- end
151
-
152
- it 'returns the unmodified value' do
153
- m = MVar.new(14)
154
- m.modify{ |v| v + 2 }.should eq 14
155
- end
156
-
157
- it 'waits for another thread to #put' do
158
- m = MVar.new
159
-
160
- putter = Thread.new {
161
- sleep(0.1)
162
- m.put 14
163
- }
164
-
165
- m.modify{ |v| v + 2 }.should eq 14
166
- end
167
-
168
- it 'is atomic' do
169
- m = MVar.new(0)
170
-
171
- # #modify conceptually does #take and #put - but it should be atomic.
172
- # Check that another #put can't sneak it during the #modify.
173
-
174
- modifier = Thread.new {
175
- m.modify do |v|
176
- sleep(0.5)
177
- 1
178
- end
179
- }
180
-
181
- sleep(0.1)
182
- m.put(2, 0.5).should eq MVar::TIMEOUT
183
- m.take.should eq 1
184
- end
185
-
186
- it 'returns TIMEOUT on timeout on an empty MVar' do
187
- m = MVar.new
188
- m.modify(0.1){ |v| v + 2 }.should eq MVar::TIMEOUT
189
- end
190
-
191
- end
192
-
193
- describe '#try_put!' do
194
-
195
- it 'returns true an empty MVar' do
196
- m = MVar.new
197
- m.try_put!(14).should eq true
198
- end
199
-
200
- it 'returns false on a full MVar' do
201
- m = MVar.new(14)
202
- m.try_put!(14).should eq false
203
- end
204
-
205
- it 'sets an empty MVar to be full' do
206
- m = MVar.new
207
- m.try_put! 14
208
- m.should be_full
209
- end
210
-
211
- end
212
-
213
- describe '#try_take!' do
214
-
215
- it 'returns EMPTY an empty MVar' do
216
- m = MVar.new
217
- m.try_take!.should eq MVar::EMPTY
218
- end
219
-
220
- it 'returns the value on a full MVar' do
221
- m = MVar.new(14)
222
- m.try_take!.should eq 14
223
- end
224
-
225
- it 'sets a full MVar to be empty' do
226
- m = MVar.new(14)
227
- m.try_take!
228
- m.should be_empty
229
- end
230
-
231
- end
232
-
233
- describe '#set!' do
234
-
235
- it 'sets an empty MVar to be full' do
236
- m = MVar.new
237
- m.set! 14
238
- m.should be_full
239
- end
240
-
241
- it 'sets a full MVar to be full' do
242
- m = MVar.new(2)
243
- m.set! 14
244
- m.should be_full
245
- m.take.should eq 14
246
- end
247
-
248
- it 'returns EMPTY on an empty MVar' do
249
- m = MVar.new
250
- m.set!(2).should eq MVar::EMPTY
251
- end
252
-
253
- it 'returns the original value on a full MVar' do
254
- m = MVar.new(14)
255
- m.set!(2).should eq 14
256
- end
257
-
258
- end
259
-
260
- describe '#modify!' do
261
-
262
- it 'raises an exception when no block given' do
263
- m = MVar.new(14)
264
- expect { m.modify! }.to raise_error(ArgumentError)
265
- end
266
-
267
- it 'modifies a full MVar' do
268
- m = MVar.new(14)
269
- m.modify!{ |v| v + 2 }
270
- m.take.should eq 16
271
- end
272
-
273
- it 'modifies an empty MVar' do
274
- m = MVar.new
275
- m.modify!{ |v| 14 }
276
- m.take.should eq 14
277
- end
278
-
279
- it 'can be used to set a full MVar to empty' do
280
- m = MVar.new(14)
281
- m.modify!{ |v| MVar::EMPTY }
282
- m.should be_empty
283
- end
284
-
285
- it 'can be used to set an empty MVar to empty' do
286
- m = MVar.new
287
- m.modify!{ |v| MVar::EMPTY }
288
- m.should be_empty
289
- end
290
-
291
- it 'returns the unmodified value' do
292
- m = MVar.new(14)
293
- m.modify!{ |v| v + 2 }.should eq 14
294
- end
295
-
296
- end
297
-
298
- context 'spurious wake ups' do
299
-
300
- let(:m) { MVar.new }
301
-
302
- before(:each) do
303
- def m.simulate_spurious_wake_up
304
- @mutex.synchronize do
305
- @full_condition.broadcast
306
- @empty_condition.broadcast
307
- end
308
- end
309
- end
310
-
311
- describe '#take' do
312
- it 'waits for another thread to #put' do
313
- Thread.new { sleep(0.5); m.put 14 }
314
- Thread.new { sleep(0.1); m.simulate_spurious_wake_up }
315
-
316
- m.take.should eq 14
317
- end
318
-
319
- it 'returns TIMEOUT on timeout on an empty MVar' do
320
- result = nil
321
- Thread.new { result = m.take(0.3) }
322
- sleep(0.1)
323
- Thread.new { m.simulate_spurious_wake_up }
324
- sleep(0.1)
325
- result.should be_nil
326
- sleep(0.2)
327
- result.should eq MVar::TIMEOUT
328
- end
329
- end
330
-
331
- describe '#modify' do
332
-
333
- it 'waits for another thread to #put' do
334
- Thread.new { sleep(0.5); m.put 14 }
335
- Thread.new { sleep(0.1); m.simulate_spurious_wake_up }
336
-
337
- m.modify{ |v| v + 2 }.should eq 14
338
- end
339
-
340
- it 'returns TIMEOUT on timeout on an empty MVar' do
341
- result = nil
342
- Thread.new { result = m.modify(0.3){ |v| v + 2 } }
343
- sleep(0.1)
344
- Thread.new { m.simulate_spurious_wake_up }
345
- sleep(0.1)
346
- result.should be_nil
347
- sleep(0.2)
348
- result.should eq MVar::TIMEOUT
349
- end
350
- end
351
-
352
- describe '#put' do
353
-
354
- before(:each) { m.put(42) }
355
-
356
- it 'waits for another thread to #take' do
357
- Thread.new { sleep(0.5); m.take }
358
- Thread.new { sleep(0.1); m.simulate_spurious_wake_up }
359
-
360
- m.put(14).should eq 14
361
- end
362
-
363
- it 'returns TIMEOUT on timeout on a full MVar' do
364
- result = nil
365
- Thread.new { result = m.put(14, 0.3) }
366
- sleep(0.1)
367
- Thread.new { m.simulate_spurious_wake_up }
368
- sleep(0.1)
369
- result.should be_nil
370
- sleep(0.2)
371
- result.should eq MVar::TIMEOUT
372
- end
373
- end
374
-
375
-
376
- end
377
-
378
- end
379
-
380
- end
@@ -1,102 +0,0 @@
1
- require 'spec_helper'
2
-
3
- share_examples_for :obligation do
4
-
5
- context '#state' do
6
-
7
- it 'is :pending when first created' do
8
- f = pending_subject
9
- f.state.should == :pending
10
- f.should be_pending
11
- end
12
-
13
- it 'is :fulfilled when the handler completes' do
14
- f = fulfilled_subject
15
- f.state.should == :fulfilled
16
- f.should be_fulfilled
17
- end
18
-
19
- it 'is :rejected when the handler raises an exception' do
20
- f = rejected_subject
21
- f.state.should == :rejected
22
- f.should be_rejected
23
- end
24
- end
25
-
26
- context '#value' do
27
-
28
- let!(:supports_timeout) { pending_subject.method(:value).arity != 0 }
29
-
30
- it 'returns nil when reaching the optional timeout value' do
31
- if supports_timeout
32
- f = pending_subject
33
- f.value(0).should be_nil
34
- f.should be_pending
35
- end
36
- end
37
-
38
- it 'returns immediately when timeout is zero' do
39
- if supports_timeout
40
- Concurrent.should_not_receive(:timeout).with(any_args())
41
- f = pending_subject
42
- f.value(0).should be_nil
43
- f.should be_pending
44
- end
45
- end
46
-
47
- it 'returns the value when fulfilled before timeout' do
48
- if supports_timeout
49
- f = pending_subject
50
- f.value(10).should be_true
51
- f.should be_fulfilled
52
- end
53
- end
54
-
55
- it 'returns nil when timeout reached' do
56
- if supports_timeout
57
- f = pending_subject
58
- f.value(0.1).should be_nil
59
- f.should be_pending
60
- end
61
- end
62
-
63
- it 'is nil when :pending' do
64
- if supports_timeout
65
- expected = pending_subject.value(0)
66
- expected.should be_nil
67
- end
68
- end
69
-
70
- it 'blocks the caller when :pending and timeout is nil' do
71
- f = pending_subject
72
- f.value.should be_true
73
- f.should be_fulfilled
74
- end
75
-
76
- it 'is nil when :rejected' do
77
- expected = rejected_subject.value
78
- expected.should be_nil
79
- end
80
-
81
- it 'is set to the return value of the block when :fulfilled' do
82
- expected = fulfilled_subject.value
83
- expected.should eq fulfilled_value
84
- end
85
- end
86
-
87
- context '#reason' do
88
-
89
- it 'is nil when :pending' do
90
- pending_subject.reason.should be_nil
91
- end
92
-
93
- it 'is nil when :fulfilled' do
94
- fulfilled_subject.reason.should be_nil
95
- end
96
-
97
- it 'is set to error object of the exception when :rejected' do
98
- rejected_subject.reason.should be_a(Exception)
99
- rejected_subject.reason.to_s.should =~ /#{rejected_reason}/
100
- end
101
- end
102
- end