concurrent-ruby 0.5.0 → 0.6.0.pre.1

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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +88 -77
  3. data/lib/concurrent.rb +17 -2
  4. data/lib/concurrent/actor.rb +17 -0
  5. data/lib/concurrent/actor_context.rb +31 -0
  6. data/lib/concurrent/actor_ref.rb +39 -0
  7. data/lib/concurrent/agent.rb +12 -3
  8. data/lib/concurrent/async.rb +290 -0
  9. data/lib/concurrent/atomic.rb +5 -9
  10. data/lib/concurrent/cached_thread_pool.rb +39 -137
  11. data/lib/concurrent/channel/blocking_ring_buffer.rb +60 -0
  12. data/lib/concurrent/channel/buffered_channel.rb +83 -0
  13. data/lib/concurrent/channel/channel.rb +11 -0
  14. data/lib/concurrent/channel/probe.rb +19 -0
  15. data/lib/concurrent/channel/ring_buffer.rb +54 -0
  16. data/lib/concurrent/channel/unbuffered_channel.rb +34 -0
  17. data/lib/concurrent/channel/waitable_list.rb +38 -0
  18. data/lib/concurrent/configuration.rb +92 -0
  19. data/lib/concurrent/dataflow.rb +9 -3
  20. data/lib/concurrent/delay.rb +88 -0
  21. data/lib/concurrent/exchanger.rb +31 -0
  22. data/lib/concurrent/fixed_thread_pool.rb +28 -122
  23. data/lib/concurrent/future.rb +10 -5
  24. data/lib/concurrent/immediate_executor.rb +3 -2
  25. data/lib/concurrent/ivar.rb +2 -1
  26. data/lib/concurrent/java_cached_thread_pool.rb +45 -0
  27. data/lib/concurrent/java_fixed_thread_pool.rb +37 -0
  28. data/lib/concurrent/java_thread_pool_executor.rb +194 -0
  29. data/lib/concurrent/per_thread_executor.rb +23 -0
  30. data/lib/concurrent/postable.rb +2 -0
  31. data/lib/concurrent/processor_count.rb +125 -0
  32. data/lib/concurrent/promise.rb +42 -18
  33. data/lib/concurrent/ruby_cached_thread_pool.rb +37 -0
  34. data/lib/concurrent/ruby_fixed_thread_pool.rb +31 -0
  35. data/lib/concurrent/ruby_thread_pool_executor.rb +268 -0
  36. data/lib/concurrent/ruby_thread_pool_worker.rb +69 -0
  37. data/lib/concurrent/simple_actor_ref.rb +124 -0
  38. data/lib/concurrent/thread_local_var.rb +1 -1
  39. data/lib/concurrent/thread_pool_executor.rb +30 -0
  40. data/lib/concurrent/timer_task.rb +13 -10
  41. data/lib/concurrent/tvar.rb +212 -0
  42. data/lib/concurrent/utilities.rb +1 -0
  43. data/lib/concurrent/version.rb +1 -1
  44. data/spec/concurrent/actor_context_spec.rb +37 -0
  45. data/spec/concurrent/actor_ref_shared.rb +313 -0
  46. data/spec/concurrent/actor_spec.rb +9 -1
  47. data/spec/concurrent/agent_spec.rb +97 -96
  48. data/spec/concurrent/async_spec.rb +320 -0
  49. data/spec/concurrent/cached_thread_pool_shared.rb +137 -0
  50. data/spec/concurrent/channel/blocking_ring_buffer_spec.rb +149 -0
  51. data/spec/concurrent/channel/buffered_channel_spec.rb +151 -0
  52. data/spec/concurrent/channel/channel_spec.rb +37 -0
  53. data/spec/concurrent/channel/probe_spec.rb +49 -0
  54. data/spec/concurrent/channel/ring_buffer_spec.rb +126 -0
  55. data/spec/concurrent/channel/unbuffered_channel_spec.rb +132 -0
  56. data/spec/concurrent/configuration_spec.rb +134 -0
  57. data/spec/concurrent/dataflow_spec.rb +109 -27
  58. data/spec/concurrent/delay_spec.rb +77 -0
  59. data/spec/concurrent/exchanger_spec.rb +66 -0
  60. data/spec/concurrent/fixed_thread_pool_shared.rb +136 -0
  61. data/spec/concurrent/future_spec.rb +60 -51
  62. data/spec/concurrent/global_thread_pool_shared.rb +33 -0
  63. data/spec/concurrent/immediate_executor_spec.rb +4 -25
  64. data/spec/concurrent/ivar_spec.rb +36 -23
  65. data/spec/concurrent/java_cached_thread_pool_spec.rb +64 -0
  66. data/spec/concurrent/java_fixed_thread_pool_spec.rb +64 -0
  67. data/spec/concurrent/java_thread_pool_executor_spec.rb +71 -0
  68. data/spec/concurrent/obligation_shared.rb +32 -20
  69. data/spec/concurrent/{global_thread_pool_spec.rb → per_thread_executor_spec.rb} +9 -13
  70. data/spec/concurrent/processor_count_spec.rb +20 -0
  71. data/spec/concurrent/promise_spec.rb +29 -41
  72. data/spec/concurrent/ruby_cached_thread_pool_spec.rb +69 -0
  73. data/spec/concurrent/ruby_fixed_thread_pool_spec.rb +39 -0
  74. data/spec/concurrent/ruby_thread_pool_executor_spec.rb +183 -0
  75. data/spec/concurrent/simple_actor_ref_spec.rb +219 -0
  76. data/spec/concurrent/thread_pool_class_cast_spec.rb +40 -0
  77. data/spec/concurrent/thread_pool_executor_shared.rb +155 -0
  78. data/spec/concurrent/thread_pool_shared.rb +98 -36
  79. data/spec/concurrent/tvar_spec.rb +137 -0
  80. data/spec/spec_helper.rb +4 -0
  81. data/spec/support/functions.rb +4 -0
  82. metadata +85 -20
  83. data/lib/concurrent/cached_thread_pool/worker.rb +0 -91
  84. data/lib/concurrent/channel.rb +0 -63
  85. data/lib/concurrent/fixed_thread_pool/worker.rb +0 -54
  86. data/lib/concurrent/global_thread_pool.rb +0 -42
  87. data/spec/concurrent/cached_thread_pool_spec.rb +0 -101
  88. data/spec/concurrent/channel_spec.rb +0 -86
  89. data/spec/concurrent/fixed_thread_pool_spec.rb +0 -92
  90. data/spec/concurrent/uses_global_thread_pool_shared.rb +0 -64
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+
3
+ module Concurrent
4
+
5
+ describe TVar do
6
+
7
+ context '#initialize' do
8
+
9
+ it 'accepts an initial value' do
10
+ t = TVar.new(14)
11
+ t.value.should eq 14
12
+ end
13
+
14
+ end
15
+
16
+ context '#value' do
17
+
18
+ it 'gets the value' do
19
+ t = TVar.new(14)
20
+ t.value.should eq 14
21
+ end
22
+
23
+ end
24
+
25
+ context '#value=' do
26
+
27
+ it 'sets the value' do
28
+ t = TVar.new(14)
29
+ t.value = 2
30
+ t.value.should eq 2
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ describe '#atomically' do
38
+
39
+ it 'raises an exception when no block given' do
40
+ expect { Concurrent::atomically }.to raise_error(ArgumentError)
41
+ end
42
+
43
+ it 'retries on abort' do
44
+ count = 0
45
+
46
+ Concurrent::atomically do
47
+ if count == 0
48
+ count = 1
49
+ Concurrent::abort_transaction
50
+ else
51
+ count = 2
52
+ end
53
+ end
54
+
55
+ count.should eq 2
56
+ end
57
+
58
+ it 'commits writes if the transaction succeeds' do
59
+ t = TVar.new(0)
60
+
61
+ Concurrent::atomically do
62
+ t.value = 1
63
+ end
64
+
65
+ t.value.should eq 1
66
+ end
67
+
68
+ it 'undoes writes if the transaction is aborted' do
69
+ t = TVar.new(0)
70
+
71
+ count = 0
72
+
73
+ Concurrent::atomically do
74
+ if count == 0
75
+ t.value = 1
76
+ count = 1
77
+ Concurrent::abort_transaction
78
+ end
79
+ end
80
+
81
+ t.value.should eq 0
82
+ end
83
+
84
+ it 'provides atomicity' do
85
+ t1 = TVar.new(0)
86
+ t2 = TVar.new(0)
87
+
88
+ count = 0
89
+
90
+ Concurrent::atomically do
91
+ if count == 0
92
+ count = 1
93
+ t1.value = 1
94
+ Concurrent::abort_transaction
95
+ t2.value = 2
96
+ end
97
+ end
98
+
99
+ t1.value.should eq 0
100
+ t2.value.should eq 0
101
+ end
102
+
103
+ it 'provides isolation' do
104
+ t = TVar.new(0)
105
+
106
+ Thread.new do
107
+ Concurrent::atomically do
108
+ t1.value = 1
109
+ sleep(1)
110
+ end
111
+ end
112
+
113
+ sleep(0.5)
114
+
115
+ t.value.should eq 0
116
+ end
117
+
118
+ it 'nests' do
119
+ Concurrent::atomically do
120
+ Concurrent::atomically do
121
+ Concurrent::atomically do
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+ end
128
+
129
+ describe '#abort_transaction' do
130
+
131
+ it 'raises an exception outside an #atomically block' do
132
+ expect { Concurrent::abort_transaction }.to raise_error(Concurrent::AbortError)
133
+ end
134
+
135
+ end
136
+
137
+ end
@@ -27,6 +27,7 @@ RSpec.configure do |config|
27
27
  end
28
28
 
29
29
  config.before(:each) do
30
+ reset_gem_configuration
30
31
  end
31
32
 
32
33
  config.after(:each) do
@@ -34,4 +35,7 @@ RSpec.configure do |config|
34
35
  thread.kill unless thread == Thread.current
35
36
  end
36
37
  end
38
+
39
+ config.after(:suite) do
40
+ end
37
41
  end
@@ -19,3 +19,7 @@ end
19
19
  def rbx?
20
20
  RbConfig::CONFIG['ruby_install_name']=~ /^rbx$/i
21
21
  end
22
+
23
+ def reset_gem_configuration
24
+ Concurrent.instance_variable_set(:@configuration, Concurrent::Configuration.new)
25
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concurrent-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry D'Antonio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-16 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Modern concurrency tools including agents, futures, promises, thread pools, actors, supervisors, and more.
@@ -24,71 +24,114 @@ files:
24
24
  - README.md
25
25
  - lib/concurrent.rb
26
26
  - lib/concurrent/actor.rb
27
+ - lib/concurrent/actor_context.rb
28
+ - lib/concurrent/actor_ref.rb
27
29
  - lib/concurrent/agent.rb
30
+ - lib/concurrent/async.rb
28
31
  - lib/concurrent/atomic.rb
29
32
  - lib/concurrent/cached_thread_pool.rb
30
- - lib/concurrent/cached_thread_pool/worker.rb
31
- - lib/concurrent/channel.rb
33
+ - lib/concurrent/channel/blocking_ring_buffer.rb
34
+ - lib/concurrent/channel/buffered_channel.rb
35
+ - lib/concurrent/channel/channel.rb
36
+ - lib/concurrent/channel/probe.rb
37
+ - lib/concurrent/channel/ring_buffer.rb
38
+ - lib/concurrent/channel/unbuffered_channel.rb
39
+ - lib/concurrent/channel/waitable_list.rb
32
40
  - lib/concurrent/condition.rb
41
+ - lib/concurrent/configuration.rb
33
42
  - lib/concurrent/copy_on_notify_observer_set.rb
34
43
  - lib/concurrent/copy_on_write_observer_set.rb
35
44
  - lib/concurrent/count_down_latch.rb
36
45
  - lib/concurrent/dataflow.rb
46
+ - lib/concurrent/delay.rb
37
47
  - lib/concurrent/dereferenceable.rb
38
48
  - lib/concurrent/event.rb
49
+ - lib/concurrent/exchanger.rb
39
50
  - lib/concurrent/fixed_thread_pool.rb
40
- - lib/concurrent/fixed_thread_pool/worker.rb
41
51
  - lib/concurrent/future.rb
42
- - lib/concurrent/global_thread_pool.rb
43
52
  - lib/concurrent/immediate_executor.rb
44
53
  - lib/concurrent/ivar.rb
54
+ - lib/concurrent/java_cached_thread_pool.rb
55
+ - lib/concurrent/java_fixed_thread_pool.rb
56
+ - lib/concurrent/java_thread_pool_executor.rb
45
57
  - lib/concurrent/mvar.rb
46
58
  - lib/concurrent/obligation.rb
59
+ - lib/concurrent/per_thread_executor.rb
47
60
  - lib/concurrent/postable.rb
61
+ - lib/concurrent/processor_count.rb
48
62
  - lib/concurrent/promise.rb
63
+ - lib/concurrent/ruby_cached_thread_pool.rb
64
+ - lib/concurrent/ruby_fixed_thread_pool.rb
65
+ - lib/concurrent/ruby_thread_pool_executor.rb
66
+ - lib/concurrent/ruby_thread_pool_worker.rb
49
67
  - lib/concurrent/runnable.rb
50
68
  - lib/concurrent/safe_task_executor.rb
51
69
  - lib/concurrent/scheduled_task.rb
70
+ - lib/concurrent/simple_actor_ref.rb
52
71
  - lib/concurrent/stoppable.rb
53
72
  - lib/concurrent/supervisor.rb
54
73
  - lib/concurrent/thread_local_var.rb
74
+ - lib/concurrent/thread_pool_executor.rb
55
75
  - lib/concurrent/timer_task.rb
76
+ - lib/concurrent/tvar.rb
56
77
  - lib/concurrent/utilities.rb
57
78
  - lib/concurrent/version.rb
58
79
  - lib/concurrent_ruby.rb
80
+ - spec/concurrent/actor_context_spec.rb
81
+ - spec/concurrent/actor_ref_shared.rb
59
82
  - spec/concurrent/actor_spec.rb
60
83
  - spec/concurrent/agent_spec.rb
84
+ - spec/concurrent/async_spec.rb
61
85
  - spec/concurrent/atomic_spec.rb
62
- - spec/concurrent/cached_thread_pool_spec.rb
63
- - spec/concurrent/channel_spec.rb
86
+ - spec/concurrent/cached_thread_pool_shared.rb
87
+ - spec/concurrent/channel/blocking_ring_buffer_spec.rb
88
+ - spec/concurrent/channel/buffered_channel_spec.rb
89
+ - spec/concurrent/channel/channel_spec.rb
90
+ - spec/concurrent/channel/probe_spec.rb
91
+ - spec/concurrent/channel/ring_buffer_spec.rb
92
+ - spec/concurrent/channel/unbuffered_channel_spec.rb
64
93
  - spec/concurrent/condition_spec.rb
94
+ - spec/concurrent/configuration_spec.rb
65
95
  - spec/concurrent/copy_on_notify_observer_set_spec.rb
66
96
  - spec/concurrent/copy_on_write_observer_set_spec.rb
67
97
  - spec/concurrent/count_down_latch_spec.rb
68
98
  - spec/concurrent/dataflow_spec.rb
99
+ - spec/concurrent/delay_spec.rb
69
100
  - spec/concurrent/dereferenceable_shared.rb
70
101
  - spec/concurrent/event_spec.rb
71
- - spec/concurrent/fixed_thread_pool_spec.rb
102
+ - spec/concurrent/exchanger_spec.rb
103
+ - spec/concurrent/fixed_thread_pool_shared.rb
72
104
  - spec/concurrent/future_spec.rb
73
- - spec/concurrent/global_thread_pool_spec.rb
105
+ - spec/concurrent/global_thread_pool_shared.rb
74
106
  - spec/concurrent/immediate_executor_spec.rb
75
107
  - spec/concurrent/ivar_spec.rb
108
+ - spec/concurrent/java_cached_thread_pool_spec.rb
109
+ - spec/concurrent/java_fixed_thread_pool_spec.rb
110
+ - spec/concurrent/java_thread_pool_executor_spec.rb
76
111
  - spec/concurrent/mvar_spec.rb
77
112
  - spec/concurrent/obligation_shared.rb
78
113
  - spec/concurrent/obligation_spec.rb
79
114
  - spec/concurrent/observer_set_shared.rb
115
+ - spec/concurrent/per_thread_executor_spec.rb
80
116
  - spec/concurrent/postable_shared.rb
117
+ - spec/concurrent/processor_count_spec.rb
81
118
  - spec/concurrent/promise_spec.rb
119
+ - spec/concurrent/ruby_cached_thread_pool_spec.rb
120
+ - spec/concurrent/ruby_fixed_thread_pool_spec.rb
121
+ - spec/concurrent/ruby_thread_pool_executor_spec.rb
82
122
  - spec/concurrent/runnable_shared.rb
83
123
  - spec/concurrent/runnable_spec.rb
84
124
  - spec/concurrent/safe_task_executor_spec.rb
85
125
  - spec/concurrent/scheduled_task_spec.rb
126
+ - spec/concurrent/simple_actor_ref_spec.rb
86
127
  - spec/concurrent/stoppable_shared.rb
87
128
  - spec/concurrent/supervisor_spec.rb
88
129
  - spec/concurrent/thread_local_var_spec.rb
130
+ - spec/concurrent/thread_pool_class_cast_spec.rb
131
+ - spec/concurrent/thread_pool_executor_shared.rb
89
132
  - spec/concurrent/thread_pool_shared.rb
90
133
  - spec/concurrent/timer_task_spec.rb
91
- - spec/concurrent/uses_global_thread_pool_shared.rb
134
+ - spec/concurrent/tvar_spec.rb
92
135
  - spec/concurrent/utilities_spec.rb
93
136
  - spec/spec_helper.rb
94
137
  - spec/support/functions.rb
@@ -105,54 +148,76 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
148
  requirements:
106
149
  - - '>='
107
150
  - !ruby/object:Gem::Version
108
- version: 1.9.2
151
+ version: 1.9.3
109
152
  required_rubygems_version: !ruby/object:Gem::Requirement
110
153
  requirements:
111
- - - '>='
154
+ - - '>'
112
155
  - !ruby/object:Gem::Version
113
- version: '0'
156
+ version: 1.3.1
114
157
  requirements: []
115
158
  rubyforge_project:
116
159
  rubygems_version: 2.2.2
117
160
  signing_key:
118
161
  specification_version: 4
119
- summary: Modern concurrency tools including agents, futures, promises, thread pools, actors, and more.
162
+ summary: Modern concurrency tools for Ruby. Inspired by Erlang, Clojure, Scala, Haskell, F#, C#, Java, and classic concurrency patterns.
120
163
  test_files:
121
164
  - spec/spec_helper.rb
165
+ - spec/concurrent/actor_context_spec.rb
166
+ - spec/concurrent/actor_ref_shared.rb
122
167
  - spec/concurrent/actor_spec.rb
123
168
  - spec/concurrent/agent_spec.rb
169
+ - spec/concurrent/async_spec.rb
124
170
  - spec/concurrent/atomic_spec.rb
125
- - spec/concurrent/cached_thread_pool_spec.rb
126
- - spec/concurrent/channel_spec.rb
171
+ - spec/concurrent/cached_thread_pool_shared.rb
127
172
  - spec/concurrent/condition_spec.rb
173
+ - spec/concurrent/configuration_spec.rb
128
174
  - spec/concurrent/copy_on_notify_observer_set_spec.rb
129
175
  - spec/concurrent/copy_on_write_observer_set_spec.rb
130
176
  - spec/concurrent/count_down_latch_spec.rb
131
177
  - spec/concurrent/dataflow_spec.rb
178
+ - spec/concurrent/delay_spec.rb
132
179
  - spec/concurrent/dereferenceable_shared.rb
133
180
  - spec/concurrent/event_spec.rb
134
- - spec/concurrent/fixed_thread_pool_spec.rb
181
+ - spec/concurrent/exchanger_spec.rb
182
+ - spec/concurrent/fixed_thread_pool_shared.rb
135
183
  - spec/concurrent/future_spec.rb
136
- - spec/concurrent/global_thread_pool_spec.rb
184
+ - spec/concurrent/global_thread_pool_shared.rb
137
185
  - spec/concurrent/immediate_executor_spec.rb
138
186
  - spec/concurrent/ivar_spec.rb
187
+ - spec/concurrent/java_cached_thread_pool_spec.rb
188
+ - spec/concurrent/java_fixed_thread_pool_spec.rb
189
+ - spec/concurrent/java_thread_pool_executor_spec.rb
139
190
  - spec/concurrent/mvar_spec.rb
140
191
  - spec/concurrent/obligation_shared.rb
141
192
  - spec/concurrent/obligation_spec.rb
142
193
  - spec/concurrent/observer_set_shared.rb
194
+ - spec/concurrent/per_thread_executor_spec.rb
143
195
  - spec/concurrent/postable_shared.rb
196
+ - spec/concurrent/processor_count_spec.rb
144
197
  - spec/concurrent/promise_spec.rb
198
+ - spec/concurrent/ruby_cached_thread_pool_spec.rb
199
+ - spec/concurrent/ruby_fixed_thread_pool_spec.rb
200
+ - spec/concurrent/ruby_thread_pool_executor_spec.rb
145
201
  - spec/concurrent/runnable_shared.rb
146
202
  - spec/concurrent/runnable_spec.rb
147
203
  - spec/concurrent/safe_task_executor_spec.rb
148
204
  - spec/concurrent/scheduled_task_spec.rb
205
+ - spec/concurrent/simple_actor_ref_spec.rb
149
206
  - spec/concurrent/stoppable_shared.rb
150
207
  - spec/concurrent/supervisor_spec.rb
151
208
  - spec/concurrent/thread_local_var_spec.rb
209
+ - spec/concurrent/thread_pool_class_cast_spec.rb
210
+ - spec/concurrent/thread_pool_executor_shared.rb
152
211
  - spec/concurrent/thread_pool_shared.rb
153
212
  - spec/concurrent/timer_task_spec.rb
154
- - spec/concurrent/uses_global_thread_pool_shared.rb
213
+ - spec/concurrent/tvar_spec.rb
155
214
  - spec/concurrent/utilities_spec.rb
215
+ - spec/concurrent/channel/blocking_ring_buffer_spec.rb
216
+ - spec/concurrent/channel/buffered_channel_spec.rb
217
+ - spec/concurrent/channel/channel_spec.rb
218
+ - spec/concurrent/channel/probe_spec.rb
219
+ - spec/concurrent/channel/ring_buffer_spec.rb
220
+ - spec/concurrent/channel/unbuffered_channel_spec.rb
156
221
  - spec/support/functions.rb
157
222
  - spec/support/less_than_or_equal_to_matcher.rb
158
223
  has_rdoc:
@@ -1,91 +0,0 @@
1
- require 'thread'
2
-
3
- module Concurrent
4
-
5
- class CachedThreadPool
6
-
7
- class Worker
8
-
9
- def initialize(parent)
10
- @parent = parent
11
- @mutex = Mutex.new
12
- @idletime = Time.now
13
- @resource = ConditionVariable.new
14
- @tasks = Queue.new
15
- end
16
-
17
- def idle?
18
- return ! @idletime.nil?
19
- end
20
-
21
- def dead?
22
- return @mutex.synchronize do
23
- @thread.nil? ? false : ! @thread.alive?
24
- end
25
- end
26
-
27
- def idletime
28
- return @mutex.synchronize do
29
- @idletime.nil? ? 0 : Time.now.to_i - @idletime.to_i
30
- end
31
- end
32
-
33
- def signal(*args, &block)
34
- return @mutex.synchronize do
35
- break(false) if @parent.nil?
36
- @tasks << [args, block]
37
- @resource.signal
38
- true
39
- end
40
- end
41
-
42
- def stop
43
- return @mutex.synchronize do
44
- @tasks.clear
45
- @tasks << :stop
46
- @resource.signal
47
- end
48
- end
49
-
50
- def kill
51
- @mutex.synchronize do
52
- @idletime = Time.now
53
- @parent = nil
54
- Thread.kill(@thread) unless @thread.nil?
55
- @thread = nil
56
- end
57
- end
58
-
59
- def run(thread = Thread.current)
60
- @mutex.synchronize do
61
- raise StandardError.new('already running') unless @thread.nil?
62
- @thread = thread
63
- end
64
-
65
- loop do
66
- task = @mutex.synchronize do
67
- @resource.wait(@mutex, 60) if @tasks.empty?
68
-
69
- @tasks.pop(true)
70
- end
71
-
72
- if task == :stop
73
- @thread = nil
74
- @parent.on_worker_exit(self)
75
- @parent = nil
76
- break
77
- end
78
-
79
- #@parent.on_start_task(self)
80
- begin
81
- task.last.call(*task.first)
82
- rescue
83
- # let it fail
84
- ensure
85
- @parent.on_end_task(self)
86
- end
87
- end
88
- end
89
- end
90
- end
91
- end