concurrent-ruby 0.6.1 → 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 (94) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/concurrent.rb +3 -4
  4. data/lib/concurrent/atomic.rb +46 -0
  5. data/lib/concurrent/atomic_reference/concurrent_update_error.rb +7 -0
  6. data/lib/concurrent/atomic_reference/delegated_update.rb +28 -0
  7. data/lib/concurrent/atomic_reference/direct_update.rb +28 -0
  8. data/lib/concurrent/atomic_reference/jruby.rb +8 -0
  9. data/lib/concurrent/atomic_reference/mutex_atomic.rb +47 -0
  10. data/lib/concurrent/atomic_reference/numeric_cas_wrapper.rb +24 -0
  11. data/lib/concurrent/atomic_reference/rbx.rb +16 -0
  12. data/lib/concurrent/atomic_reference/ruby.rb +16 -0
  13. data/lib/concurrent/atomics.rb +1 -1
  14. data/lib/concurrent/configuration.rb +1 -1
  15. data/lib/concurrent/supervisor.rb +1 -1
  16. data/lib/concurrent/timer_task.rb +0 -36
  17. data/lib/concurrent/version.rb +1 -1
  18. data/lib/concurrent_ruby_ext.so +0 -0
  19. data/lib/extension_helper.rb +9 -0
  20. metadata +16 -148
  21. data/lib/concurrent/actor/actor.rb +0 -270
  22. data/lib/concurrent/actor/postable.rb +0 -102
  23. data/lib/concurrent/actors.rb +0 -2
  24. data/lib/concurrent/atomic/atomic.rb +0 -48
  25. data/lib/concurrent/runnable.rb +0 -90
  26. data/lib/concurrent/stoppable.rb +0 -20
  27. data/spec/concurrent/actor/actor_spec.rb +0 -376
  28. data/spec/concurrent/actor/postable_shared.rb +0 -218
  29. data/spec/concurrent/actress_spec.rb +0 -211
  30. data/spec/concurrent/agent_spec.rb +0 -500
  31. data/spec/concurrent/async_spec.rb +0 -352
  32. data/spec/concurrent/atomic/atomic_boolean_spec.rb +0 -172
  33. data/spec/concurrent/atomic/atomic_fixnum_spec.rb +0 -186
  34. data/spec/concurrent/atomic/atomic_spec.rb +0 -133
  35. data/spec/concurrent/atomic/condition_spec.rb +0 -171
  36. data/spec/concurrent/atomic/copy_on_notify_observer_set_spec.rb +0 -10
  37. data/spec/concurrent/atomic/copy_on_write_observer_set_spec.rb +0 -10
  38. data/spec/concurrent/atomic/count_down_latch_spec.rb +0 -151
  39. data/spec/concurrent/atomic/cyclic_barrier_spec.rb +0 -248
  40. data/spec/concurrent/atomic/event_spec.rb +0 -200
  41. data/spec/concurrent/atomic/observer_set_shared.rb +0 -242
  42. data/spec/concurrent/atomic/thread_local_var_spec.rb +0 -113
  43. data/spec/concurrent/channel/buffered_channel_spec.rb +0 -151
  44. data/spec/concurrent/channel/channel_spec.rb +0 -39
  45. data/spec/concurrent/channel/probe_spec.rb +0 -77
  46. data/spec/concurrent/channel/unbuffered_channel_spec.rb +0 -132
  47. data/spec/concurrent/collection/blocking_ring_buffer_spec.rb +0 -149
  48. data/spec/concurrent/collection/priority_queue_spec.rb +0 -317
  49. data/spec/concurrent/collection/ring_buffer_spec.rb +0 -126
  50. data/spec/concurrent/configuration_spec.rb +0 -69
  51. data/spec/concurrent/dataflow_spec.rb +0 -242
  52. data/spec/concurrent/delay_spec.rb +0 -91
  53. data/spec/concurrent/dereferenceable_shared.rb +0 -146
  54. data/spec/concurrent/exchanger_spec.rb +0 -66
  55. data/spec/concurrent/executor/cached_thread_pool_shared.rb +0 -115
  56. data/spec/concurrent/executor/fixed_thread_pool_shared.rb +0 -136
  57. data/spec/concurrent/executor/global_thread_pool_shared.rb +0 -35
  58. data/spec/concurrent/executor/immediate_executor_spec.rb +0 -12
  59. data/spec/concurrent/executor/java_cached_thread_pool_spec.rb +0 -44
  60. data/spec/concurrent/executor/java_fixed_thread_pool_spec.rb +0 -64
  61. data/spec/concurrent/executor/java_single_thread_executor_spec.rb +0 -21
  62. data/spec/concurrent/executor/java_thread_pool_executor_spec.rb +0 -71
  63. data/spec/concurrent/executor/per_thread_executor_spec.rb +0 -57
  64. data/spec/concurrent/executor/ruby_cached_thread_pool_spec.rb +0 -69
  65. data/spec/concurrent/executor/ruby_fixed_thread_pool_spec.rb +0 -39
  66. data/spec/concurrent/executor/ruby_single_thread_executor_spec.rb +0 -18
  67. data/spec/concurrent/executor/ruby_thread_pool_executor_spec.rb +0 -171
  68. data/spec/concurrent/executor/safe_task_executor_spec.rb +0 -103
  69. data/spec/concurrent/executor/thread_pool_class_cast_spec.rb +0 -52
  70. data/spec/concurrent/executor/thread_pool_executor_shared.rb +0 -155
  71. data/spec/concurrent/executor/thread_pool_shared.rb +0 -269
  72. data/spec/concurrent/executor/timer_set_spec.rb +0 -183
  73. data/spec/concurrent/future_spec.rb +0 -329
  74. data/spec/concurrent/ivar_spec.rb +0 -215
  75. data/spec/concurrent/mvar_spec.rb +0 -380
  76. data/spec/concurrent/obligation_shared.rb +0 -102
  77. data/spec/concurrent/obligation_spec.rb +0 -282
  78. data/spec/concurrent/observable_shared.rb +0 -177
  79. data/spec/concurrent/observable_spec.rb +0 -56
  80. data/spec/concurrent/options_parser_spec.rb +0 -71
  81. data/spec/concurrent/promise_spec.rb +0 -367
  82. data/spec/concurrent/runnable_shared.rb +0 -68
  83. data/spec/concurrent/runnable_spec.rb +0 -235
  84. data/spec/concurrent/scheduled_task_spec.rb +0 -340
  85. data/spec/concurrent/stoppable_shared.rb +0 -37
  86. data/spec/concurrent/supervisor_spec.rb +0 -1149
  87. data/spec/concurrent/timer_task_spec.rb +0 -256
  88. data/spec/concurrent/tvar_spec.rb +0 -137
  89. data/spec/concurrent/utility/processor_count_spec.rb +0 -20
  90. data/spec/concurrent/utility/timeout_spec.rb +0 -50
  91. data/spec/concurrent/utility/timer_spec.rb +0 -52
  92. data/spec/spec_helper.rb +0 -41
  93. data/spec/support/example_group_extensions.rb +0 -52
  94. data/spec/support/less_than_or_equal_to_matcher.rb +0 -5
@@ -1,242 +0,0 @@
1
- require 'spec_helper'
2
-
3
- shared_examples "an observer set" do
4
-
5
- let (:observer_set) { described_class.new }
6
- let (:observer) { double('observer') }
7
- let (:another_observer) { double('another observer') }
8
-
9
- describe '#add_observer' do
10
-
11
- context 'with arguments' do
12
- it 'should return the observer' do
13
- observer_set.add_observer(observer, :a_method).should == observer
14
- end
15
- end
16
-
17
- context 'with a block' do
18
- it 'should return the observer based on a block' do
19
- observer = observer_set.add_observer { :block }
20
- observer.call.should == :block
21
- end
22
- end
23
- end
24
-
25
- describe '#notify_observers' do
26
- it 'should return the observer set' do
27
- observer_set.notify_observers.should be(observer_set)
28
- end
29
-
30
- context 'with a single observer' do
31
- it 'should update a registered observer without arguments' do
32
- expect(observer).to receive(:update).with(no_args)
33
-
34
- observer_set.add_observer(observer)
35
-
36
- observer_set.notify_observers
37
- end
38
-
39
- it 'should update a registered observer with arguments' do
40
- expect(observer).to receive(:update).with(1, 2, 3)
41
-
42
- observer_set.add_observer(observer)
43
-
44
- observer_set.notify_observers(1, 2, 3)
45
- end
46
-
47
- it 'should notify an observer using the chosen method' do
48
- expect(observer).to receive(:another_method).with('a string arg')
49
-
50
- observer_set.add_observer(observer, :another_method)
51
-
52
- observer_set.notify_observers('a string arg')
53
- end
54
-
55
- it 'should notify an observer once using the last added method' do
56
- expect(observer).to receive(:another_method).with(any_args).never
57
- expect(observer).to receive(:yet_another_method).with('a string arg')
58
-
59
- observer_set.add_observer(observer, :another_method)
60
- observer_set.add_observer(observer, :yet_another_method)
61
-
62
- observer_set.notify_observers('a string arg')
63
- end
64
-
65
- it 'should notify an observer from a block' do
66
- notification = double
67
- expect(notification).to receive(:catch)
68
-
69
- observer_set.add_observer {|arg| arg.catch }
70
- observer_set.notify_observers notification
71
- end
72
-
73
- it 'can be called many times' do
74
- expect(observer).to receive(:update).with(:an_arg).twice
75
- expect(observer).to receive(:update).with(no_args).once
76
-
77
- observer_set.add_observer(observer)
78
-
79
- observer_set.notify_observers(:an_arg)
80
- observer_set.notify_observers
81
- observer_set.notify_observers(:an_arg)
82
- end
83
- end
84
-
85
- context 'with many observers' do
86
- it 'should notify all observer using the chosen method' do
87
- expect(observer).to receive(:a_method).with(4, 'a')
88
- expect(another_observer).to receive(:update).with(4, 'a')
89
-
90
- observer_set.add_observer(observer, :a_method)
91
- observer_set.add_observer(another_observer)
92
-
93
- observer_set.notify_observers(4, 'a')
94
- end
95
- end
96
-
97
- context 'with a block' do
98
-
99
- before(:each) do
100
- observer.stub(:update).with(any_args)
101
- another_observer.stub(:update).with(any_args)
102
- end
103
-
104
- it 'calls the block once for every observer' do
105
-
106
- counter = double('block call counter')
107
- expect(counter).to receive(:called).with(no_args).exactly(2).times
108
-
109
- observer_set.add_observer(observer)
110
- observer_set.add_observer(another_observer)
111
-
112
- observer_set.notify_observers{ counter.called }
113
- end
114
-
115
- it 'passes the block return value to the update method' do
116
-
117
- expect(observer).to receive(:update).with(1, 2, 3, 4)
118
- observer_set.add_observer(observer)
119
- observer_set.notify_observers{ [1, 2, 3, 4] }
120
- end
121
-
122
- it 'accepts blocks returning a single value' do
123
-
124
- expect(observer).to receive(:update).with(:foo)
125
- observer_set.add_observer(observer)
126
- observer_set.notify_observers{ :foo }
127
- end
128
-
129
- it 'accepts block return values that include arrays' do
130
-
131
- expect(observer).to receive(:update).with(1, [2, 3], 4)
132
- observer_set.add_observer(observer)
133
- observer_set.notify_observers{ [1, [2, 3], 4] }
134
- end
135
-
136
- it 'raises an exception if given both arguments and a block' do
137
-
138
- observer_set.add_observer(observer)
139
-
140
- expect {
141
- observer_set.notify_observers(1, 2, 3, 4){ nil }
142
- }.to raise_error(ArgumentError)
143
- end
144
- end
145
- end
146
-
147
- context '#count_observers' do
148
- it 'should be zero after initialization' do
149
- observer_set.count_observers.should eq 0
150
- end
151
-
152
- it 'should be 1 after the first observer is added' do
153
- observer_set.add_observer(observer)
154
- observer_set.count_observers.should eq 1
155
- end
156
-
157
- it 'should be 1 if the same observer is added many times' do
158
- observer_set.add_observer(observer)
159
- observer_set.add_observer(observer, :another_method)
160
- observer_set.add_observer(observer, :yet_another_method)
161
-
162
- observer_set.count_observers.should eq 1
163
- end
164
-
165
- it 'should be equal to the number of unique observers' do
166
- observer_set.add_observer(observer)
167
- observer_set.add_observer(another_observer)
168
- observer_set.add_observer(double('observer 3'))
169
- observer_set.add_observer(double('observer 4'))
170
-
171
- observer_set.count_observers.should eq 4
172
- end
173
- end
174
-
175
- describe '#delete_observer' do
176
- it 'should not notify a deleted observer' do
177
- expect(observer).to receive(:update).never
178
-
179
- observer_set.add_observer(observer)
180
- observer_set.delete_observer(observer)
181
-
182
- observer_set.notify_observers
183
- end
184
-
185
- it 'can delete a non added observer' do
186
- observer_set.delete_observer(observer)
187
- end
188
-
189
- it 'should return the observer' do
190
- observer_set.delete_observer(observer).should be(observer)
191
- end
192
- end
193
-
194
- describe '#delete_observers' do
195
- it 'should remove all observers' do
196
- expect(observer).to receive(:update).never
197
- expect(another_observer).to receive(:update).never
198
-
199
- observer_set.add_observer(observer)
200
- observer_set.add_observer(another_observer)
201
-
202
- observer_set.delete_observers
203
-
204
- observer_set.notify_observers
205
- end
206
-
207
- it 'should return the observer set' do
208
- observer_set.delete_observers.should be(observer_set)
209
- end
210
- end
211
-
212
- describe '#notify_and_delete_observers' do
213
- before(:each) do
214
- observer_set.add_observer(observer, :a_method)
215
- observer_set.add_observer(another_observer)
216
-
217
- expect(observer).to receive(:a_method).with('args').once
218
- expect(another_observer).to receive(:update).with('args').once
219
- end
220
-
221
- it 'should notify all observers' do
222
- observer_set.notify_and_delete_observers('args')
223
- end
224
-
225
- it 'should clear observers' do
226
- observer_set.notify_and_delete_observers('args')
227
-
228
- observer_set.count_observers.should eq(0)
229
- end
230
-
231
- it 'can be called many times without any other notification' do
232
- observer_set.notify_and_delete_observers('args')
233
- observer_set.notify_and_delete_observers('args')
234
- observer_set.notify_and_delete_observers('args')
235
- end
236
-
237
- it 'should return the observer set' do
238
- observer_set.notify_and_delete_observers('args').should be(observer_set)
239
- end
240
- end
241
-
242
- end
@@ -1,113 +0,0 @@
1
- require 'spec_helper'
2
- require 'rbconfig'
3
-
4
- module Concurrent
5
-
6
- describe ThreadLocalVar do
7
-
8
- subject{ ThreadLocalVar.new }
9
-
10
- context '#initialize' do
11
-
12
- it 'can set an initial value' do
13
- v = ThreadLocalVar.new(14)
14
- v.value.should eq 14
15
- end
16
-
17
- it 'sets nil as a default initial value' do
18
- v = ThreadLocalVar.new
19
- v.value.should be_nil
20
- end
21
-
22
- it 'sets the same initial value for all threads' do
23
- v = ThreadLocalVar.new(14)
24
- t1 = Thread.new { v.value }
25
- t2 = Thread.new { v.value }
26
- t1.value.should eq 14
27
- t2.value.should eq 14
28
- end
29
-
30
- if jruby?
31
- it 'uses ThreadLocalJavaStorage' do
32
- subject.class.ancestors.should include(Concurrent::ThreadLocalJavaStorage)
33
- end
34
- elsif rbx? || RbConfig::CONFIG['ruby_version'] =~ /^1\.9/
35
- it 'uses ThreadLocalOldStorage' do
36
- subject.class.ancestors.should include(Concurrent::ThreadLocalOldStorage)
37
- end
38
- else
39
- it 'uses ThreadLocalNewStorage' do
40
- subject.class.ancestors.should include(Concurrent::ThreadLocalNewStorage)
41
- end
42
- end
43
- end
44
-
45
- context '#value' do
46
-
47
- it 'returns the current value' do
48
- v = ThreadLocalVar.new(14)
49
- v.value.should eq 14
50
- end
51
-
52
- it 'returns the value after modification' do
53
- v = ThreadLocalVar.new(14)
54
- v.value = 2
55
- v.value.should eq 2
56
- end
57
-
58
- end
59
-
60
- context '#value=' do
61
-
62
- it 'sets a new value' do
63
- v = ThreadLocalVar.new(14)
64
- v.value = 2
65
- v.value.should eq 2
66
- end
67
-
68
- it 'returns the new value' do
69
- v = ThreadLocalVar.new(14)
70
- (v.value = 2).should eq 2
71
- end
72
-
73
- it 'does not modify the initial value for other threads' do
74
- v = ThreadLocalVar.new(14)
75
- v.value = 2
76
- t = Thread.new { v.value }
77
- t.value.should eq 14
78
- end
79
-
80
- it 'does not modify the value for other threads' do
81
- v = ThreadLocalVar.new(14)
82
- v.value = 2
83
-
84
- b1 = CountDownLatch.new(2)
85
- b2 = CountDownLatch.new(2)
86
-
87
- t1 = Thread.new do
88
- b1.count_down
89
- b1.wait
90
- v.value = 1
91
- b2.count_down
92
- b2.wait
93
- v.value
94
- end
95
-
96
- t2 = Thread.new do
97
- b1.count_down
98
- b1.wait
99
- v.value = 2
100
- b2.count_down
101
- b2.wait
102
- v.value
103
- end
104
-
105
- t1.value.should eq 1
106
- t2.value.should eq 2
107
- end
108
-
109
- end
110
-
111
- end
112
-
113
- end
@@ -1,151 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Concurrent
4
-
5
- describe BufferedChannel do
6
-
7
- let(:size) { 2 }
8
- let!(:channel) { BufferedChannel.new(size) }
9
- let(:probe) { Channel::Probe.new }
10
-
11
- context 'without timeout' do
12
-
13
- describe '#push' do
14
- it 'adds elements to buffer' do
15
- channel.buffer_queue_size.should be 0
16
-
17
- channel.push('a')
18
- channel.push('a')
19
-
20
- channel.buffer_queue_size.should be 2
21
- end
22
-
23
- it 'should block when buffer is full' do
24
- channel.push 1
25
- channel.push 2
26
-
27
- t = Thread.new { channel.push 3 }
28
- sleep(0.05)
29
- t.status.should eq 'sleep'
30
- end
31
-
32
- it 'restarts thread when buffer is no more full' do
33
- channel.push 'hi'
34
- channel.push 'foo'
35
-
36
- result = nil
37
-
38
- Thread.new { channel.push 'bar'; result = 42 }
39
-
40
- sleep(0.1)
41
-
42
- channel.pop
43
-
44
- sleep(0.1)
45
-
46
- result.should eq 42
47
- end
48
-
49
- it 'should assign value to a probe if probe set is not empty' do
50
- channel.select(probe)
51
- Thread.new { sleep(0.1); channel.push 3 }
52
- probe.value.should eq 3
53
- end
54
- end
55
-
56
- describe '#pop' do
57
- it 'should block if buffer is empty' do
58
- t = Thread.new { channel.pop }
59
- sleep(0.05)
60
- t.status.should eq 'sleep'
61
- end
62
-
63
- it 'returns value if buffer is not empty' do
64
- channel.push 1
65
- result = channel.pop
66
-
67
- result.should eq 1
68
- end
69
-
70
- it 'removes the first value from the buffer' do
71
- channel.push 'a'
72
- channel.push 'b'
73
-
74
- channel.pop.should eq 'a'
75
- channel.buffer_queue_size.should eq 1
76
- end
77
- end
78
-
79
- end
80
-
81
- describe 'select' do
82
-
83
- it 'does not block' do
84
- t = Thread.new { channel.select(probe) }
85
-
86
- sleep(0.05)
87
-
88
- t.status.should eq false
89
- end
90
-
91
- it 'gets notified by writer thread' do
92
- channel.select(probe)
93
-
94
- Thread.new { channel.push 82 }
95
-
96
- probe.value.should eq 82
97
- end
98
-
99
- end
100
-
101
- context 'already set probes' do
102
- context 'empty buffer' do
103
- it 'discards already set probes' do
104
- probe.set('set value')
105
-
106
- channel.select(probe)
107
-
108
- channel.push 27
109
-
110
- channel.buffer_queue_size.should eq 1
111
- channel.probe_set_size.should eq 0
112
- end
113
- end
114
-
115
- context 'empty probe set' do
116
- it 'discards set probe' do
117
- probe.set('set value')
118
-
119
- channel.push 82
120
-
121
- channel.select(probe)
122
-
123
- channel.buffer_queue_size.should eq 1
124
-
125
- channel.pop.should eq 82
126
-
127
- end
128
- end
129
- end
130
-
131
- describe 'probe set' do
132
-
133
- it 'has size zero after creation' do
134
- channel.probe_set_size.should eq 0
135
- end
136
-
137
- it 'increases size after a select' do
138
- channel.select(probe)
139
- channel.probe_set_size.should eq 1
140
- end
141
-
142
- it 'decreases size after a removal' do
143
- channel.select(probe)
144
- channel.remove_probe(probe)
145
- channel.probe_set_size.should eq 0
146
- end
147
-
148
- end
149
-
150
- end
151
- end