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,317 +0,0 @@
1
- require 'spec_helper'
2
-
3
- share_examples_for :priority_queue do
4
-
5
- subject{ described_class.new }
6
-
7
- context '#initialize' do
8
-
9
- it 'sorts from high to low when :order is :max' do
10
- subject = described_class.from_list([2, 1, 4, 5, 3, 0], order: :max)
11
- subject.pop.should eq 5
12
- subject.pop.should eq 4
13
- subject.pop.should eq 3
14
- end
15
-
16
- it 'sorts from high to low when :order is :high' do
17
- subject = described_class.new(order: :high)
18
- [2, 1, 4, 5, 3, 0].each{|item| subject << item }
19
- subject.pop.should eq 5
20
- subject.pop.should eq 4
21
- subject.pop.should eq 3
22
- end
23
-
24
- it 'sorts from low to high when :order is :min' do
25
- subject = described_class.from_list([2, 1, 4, 5, 3, 0], order: :min)
26
- subject.pop.should eq 0
27
- subject.pop.should eq 1
28
- subject.pop.should eq 2
29
- end
30
-
31
- it 'sorts from low to high when :order is :low' do
32
- subject = described_class.new(order: :low)
33
- [2, 1, 4, 5, 3, 0].each{|item| subject << item }
34
- subject.pop.should eq 0
35
- subject.pop.should eq 1
36
- subject.pop.should eq 2
37
- end
38
-
39
- it 'sorts from high to low by default' do
40
- subject = described_class.new
41
- subject = described_class.from_list([2, 1, 4, 5, 3, 0])
42
- subject.pop.should eq 5
43
- subject.pop.should eq 4
44
- subject.pop.should eq 3
45
- end
46
- end
47
-
48
- context '#clear' do
49
-
50
- it 'removes all items from a populated queue' do
51
- 10.times{|i| subject << i}
52
- subject.clear
53
- subject.should be_empty
54
- end
55
-
56
- it 'has no effect on an empty queue' do
57
- subject.clear
58
- subject.should be_empty
59
- end
60
-
61
- specify { subject.clear.should be_true }
62
- end
63
-
64
- context '#delete' do
65
-
66
- it 'deletes the requested item when found' do
67
- 10.times{|item| subject << item }
68
- subject.delete(5)
69
- subject.pop.should eq 9
70
- subject.pop.should eq 8
71
- subject.pop.should eq 7
72
- subject.pop.should eq 6
73
- subject.pop.should eq 4
74
- subject.pop.should eq 3
75
- subject.pop.should eq 2
76
- subject.pop.should eq 1
77
- subject.pop.should eq 0
78
- end
79
-
80
- it 'deletes the requested item when it is the first element' do
81
- 10.times{|item| subject << item }
82
- subject.delete(9)
83
- subject.length.should eq 9
84
- subject.pop.should eq 8
85
- subject.pop.should eq 7
86
- subject.pop.should eq 6
87
- subject.pop.should eq 5
88
- subject.pop.should eq 4
89
- subject.pop.should eq 3
90
- subject.pop.should eq 2
91
- subject.pop.should eq 1
92
- subject.pop.should eq 0
93
- end
94
-
95
- it 'deletes the requested item when it is the last element' do
96
- 10.times{|item| subject << item }
97
- subject.delete(2)
98
- subject.length.should eq 9
99
- subject.pop.should eq 9
100
- subject.pop.should eq 8
101
- subject.pop.should eq 7
102
- subject.pop.should eq 6
103
- subject.pop.should eq 5
104
- subject.pop.should eq 4
105
- subject.pop.should eq 3
106
- subject.pop.should eq 1
107
- subject.pop.should eq 0
108
- end
109
-
110
- it 'deletes multiple matching items when present' do
111
- [2, 1, 2, 2, 2, 3, 2].each{|item| subject << item }
112
- subject.delete(2)
113
- subject.pop.should eq 3
114
- subject.pop.should eq 1
115
- end
116
-
117
- it 'returns true when found' do
118
- 10.times{|i| subject << i}
119
- subject.delete(2).should be_true
120
- end
121
-
122
- it 'returns false when not found' do
123
- 10.times{|i| subject << i}
124
- subject.delete(100).should be_false
125
- end
126
-
127
- it 'returns false when called on an empty queue' do
128
- subject.delete(:foo).should be_false
129
- end
130
- end
131
-
132
- context '#empty?' do
133
-
134
- it 'returns true for an empty queue' do
135
- subject.should be_empty
136
- end
137
-
138
- it 'returns false for a populated queue' do
139
- 10.times{|i| subject << i}
140
- subject.should_not be_empty
141
- end
142
- end
143
-
144
- context '#include?' do
145
-
146
- it 'returns true if the item is found' do
147
- 10.times{|i| subject << i}
148
- subject.should include(5)
149
- end
150
-
151
- it 'returns false if the item is not found' do
152
- 10.times{|i| subject << i}
153
- subject.should_not include(50)
154
- end
155
-
156
- it 'returns false when the queue is empty' do
157
- subject.should_not include(1)
158
- end
159
-
160
- it 'is aliased as #has_priority?' do
161
- 10.times{|i| subject << i}
162
- subject.should have_priority(5)
163
- end
164
- end
165
-
166
- context '#length' do
167
-
168
- it 'returns the length of a populated queue' do
169
- 10.times{|i| subject << i}
170
- subject.length.should eq 10
171
- end
172
-
173
- it 'returns zero when the queue is empty' do
174
- subject.length.should eq 0
175
- end
176
-
177
- it 'is aliased as #size' do
178
- 10.times{|i| subject << i}
179
- subject.size.should eq 10
180
- end
181
- end
182
-
183
- context '#peek' do
184
-
185
- it 'returns the item at the head of the queue' do
186
- 10.times{|i| subject << i}
187
- subject.peek.should eq 9
188
- end
189
-
190
- it 'does not remove the item from the queue' do
191
- 10.times{|i| subject << i}
192
- subject.peek
193
- subject.length.should eq 10
194
- subject.should include(9)
195
- end
196
-
197
- it 'returns nil when the queue is empty' do
198
- subject.peek.should be_nil
199
- end
200
- end
201
-
202
- context '#pop' do
203
-
204
- it 'returns the item at the head of the queue' do
205
- 10.times{|i| subject << i}
206
- subject.pop.should eq 9
207
- end
208
-
209
- it 'removes the item from the queue' do
210
- 10.times{|i| subject << i}
211
- subject.pop
212
- subject.length.should eq 9
213
- subject.should_not include(9)
214
- end
215
-
216
- it 'returns nil when the queue is empty' do
217
- subject.pop.should be_nil
218
- end
219
-
220
- it 'is aliased as #deq' do
221
- 10.times{|i| subject << i}
222
- subject.deq.should eq 9
223
- end
224
-
225
- it 'is aliased as #shift' do
226
- 10.times{|i| subject << i}
227
- subject.shift.should eq 9
228
- end
229
- end
230
-
231
- context '#push' do
232
-
233
- it 'adds the item to the queue' do
234
- subject.push(1)
235
- subject.should include(1)
236
- end
237
-
238
- it 'sorts the new item in priority order' do
239
- 3.times{|i| subject << i}
240
- subject.pop.should eq 2
241
- subject.pop.should eq 1
242
- subject.pop.should eq 0
243
- end
244
-
245
- it 'arbitrarily orders equal items with respect to each other' do
246
- 3.times{|i| subject << i}
247
- subject.push(1)
248
- subject.pop.should eq 2
249
- subject.pop.should eq 1
250
- subject.pop.should eq 1
251
- subject.pop.should eq 0
252
- end
253
-
254
- specify { subject.push(10).should be_true }
255
-
256
- it 'is aliased as <<' do
257
- subject << 1
258
- subject.should include(1)
259
- end
260
-
261
- it 'is aliased as enq' do
262
- subject.enq(1)
263
- subject.should include(1)
264
- end
265
- end
266
-
267
- context '.from_list' do
268
-
269
- it 'creates an empty queue from an empty list' do
270
- subject = described_class.from_list([])
271
- subject.should be_empty
272
- end
273
-
274
- it 'creates a sorted, populated queue from an Array' do
275
- subject = described_class.from_list([2, 1, 4, 5, 3, 0])
276
- subject.pop.should eq 5
277
- subject.pop.should eq 4
278
- subject.pop.should eq 3
279
- subject.pop.should eq 2
280
- subject.pop.should eq 1
281
- subject.pop.should eq 0
282
- end
283
-
284
- it 'creates a sorted, populated queue from a Hash' do
285
- subject = described_class.from_list(two: 2, one: 1, three: 3, zero: 0)
286
- subject.length.should eq 4
287
- end
288
- end
289
- end
290
-
291
- module Concurrent
292
-
293
- describe MutexPriorityQueue do
294
-
295
- it_should_behave_like :priority_queue
296
- end
297
-
298
- if TestHelpers.jruby?
299
-
300
- describe JavaPriorityQueue do
301
-
302
- it_should_behave_like :priority_queue
303
- end
304
- end
305
-
306
- describe PriorityQueue do
307
- if jruby?
308
- it 'inherits from JavaPriorityQueue' do
309
- PriorityQueue.ancestors.should include(JavaPriorityQueue)
310
- end
311
- else
312
- it 'inherits from MutexPriorityQueue' do
313
- PriorityQueue.ancestors.should include(MutexPriorityQueue)
314
- end
315
- end
316
- end
317
- end
@@ -1,126 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Concurrent
4
-
5
- describe RingBuffer do
6
-
7
- let(:capacity) { 3 }
8
- let(:buffer) { RingBuffer.new(capacity) }
9
-
10
- def fill_buffer
11
- capacity.times { buffer.offer 3 }
12
- end
13
-
14
- describe '#capacity' do
15
- it 'returns the value passed in constructor' do
16
- buffer.capacity.should eq capacity
17
- end
18
- end
19
-
20
- describe '#count' do
21
- it 'is zero when created' do
22
- buffer.count.should eq 0
23
- end
24
-
25
- it 'increases when an element is added' do
26
- buffer.offer 5
27
- buffer.count.should eq 1
28
-
29
- buffer.offer 1
30
- buffer.count.should eq 2
31
- end
32
-
33
- it 'decreases when an element is removed' do
34
- buffer.offer 10
35
- buffer.poll
36
-
37
- buffer.count.should eq 0
38
- end
39
- end
40
-
41
- describe '#empty?' do
42
- it 'is true when count is zero' do
43
- buffer.empty?.should be_true
44
- end
45
-
46
- it 'is false when count is not zero' do
47
- buffer.offer 82
48
- buffer.empty?.should be_false
49
- end
50
- end
51
-
52
- describe '#full?' do
53
- it 'is true when count is capacity' do
54
- fill_buffer
55
- buffer.full?.should be_true
56
- end
57
-
58
- it 'is false when count is not capacity' do
59
- buffer.full?.should be_false
60
- end
61
- end
62
-
63
- describe '#offer' do
64
- it 'returns false when buffer is full' do
65
- fill_buffer
66
- buffer.offer(3).should be_false
67
- end
68
-
69
- it 'returns true when the buffer is not full' do
70
- buffer.offer(5).should be_true
71
- end
72
-
73
- end
74
-
75
- describe '#poll' do
76
- it 'returns the first added value' do
77
- buffer.offer 'hi'
78
- buffer.offer 'foo'
79
- buffer.offer 'bar'
80
-
81
- buffer.poll.should eq 'hi'
82
- buffer.poll.should eq 'foo'
83
- buffer.poll.should eq 'bar'
84
- end
85
-
86
- it 'returns nil when buffer is empty' do
87
- buffer.poll.should be_nil
88
- end
89
- end
90
-
91
- describe '#peek' do
92
- context 'buffer empty' do
93
- it 'returns nil when buffer is empty' do
94
- buffer.peek.should be_nil
95
- end
96
- end
97
-
98
- context 'not empty' do
99
-
100
- before(:each) { buffer.offer 'element' }
101
-
102
- it 'returns the first value' do
103
- buffer.peek.should eq 'element'
104
- end
105
-
106
- it 'does not change buffer' do
107
- buffer.peek
108
- buffer.count.should eq 1
109
- end
110
- end
111
- end
112
-
113
- context 'circular condition' do
114
- it 'can filled many times' do
115
- fill_buffer
116
- capacity.times { buffer.poll }
117
-
118
- buffer.offer 'hi'
119
-
120
- buffer.poll.should eq 'hi'
121
- buffer.capacity.should eq capacity
122
- end
123
- end
124
-
125
- end
126
- end
@@ -1,71 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Concurrent
4
-
5
- describe Configuration do
6
- with_full_reset
7
-
8
- it 'creates a global timer pool' do
9
- Concurrent.configuration.global_timer_set.should_not be_nil
10
- Concurrent.configuration.global_timer_set.should respond_to(:post)
11
- end
12
-
13
- context 'global task pool' do
14
-
15
- specify 'reader creates a default pool when first called if none exists' do
16
- Concurrent.configuration.global_task_pool.should_not be_nil
17
- Concurrent.configuration.global_task_pool.should respond_to(:post)
18
- end
19
-
20
- specify 'writer memoizes the given executor' do
21
- executor = ImmediateExecutor.new
22
- Concurrent.configure do |config|
23
- config.global_task_pool = executor
24
- end
25
- Concurrent.configuration.global_task_pool.should eq executor
26
- end
27
-
28
- specify 'writer raises an exception if called after initialization' do
29
- executor = ImmediateExecutor.new
30
- Concurrent.configure do |config|
31
- config.global_task_pool = executor
32
- end
33
- Concurrent.configuration.global_task_pool
34
- expect {
35
- Concurrent.configure do |config|
36
- config.global_task_pool = executor
37
- end
38
- }.to raise_error(ConfigurationError)
39
- end
40
- end
41
-
42
- context 'global operation pool' do
43
-
44
- specify 'reader creates a default pool when first called if none exists' do
45
- Concurrent.configuration.global_operation_pool.should_not be_nil
46
- Concurrent.configuration.global_operation_pool.should respond_to(:post)
47
- end
48
-
49
- specify 'writer memoizes the given executor' do
50
- executor = ImmediateExecutor.new
51
- Concurrent.configure do |config|
52
- config.global_operation_pool = executor
53
- end
54
- Concurrent.configuration.global_operation_pool.should eq executor
55
- end
56
-
57
- specify 'writer raises an exception if called after initialization' do
58
- executor = ImmediateExecutor.new
59
- Concurrent.configure do |config|
60
- config.global_operation_pool = executor
61
- end
62
- Concurrent.configuration.global_operation_pool
63
- expect {
64
- Concurrent.configure do |config|
65
- config.global_operation_pool = executor
66
- end
67
- }.to raise_error(ConfigurationError)
68
- end
69
- end
70
- end
71
- end