Skip to content

Commit 194cb5a

Browse files
committed
Addressed bug with growing thread pools.
1 parent bbda753 commit 194cb5a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/concurrent/ruby_thread_pool_executor.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ def post(*args, &task)
122122
@queue << [args, task]
123123
if Time.now.to_f - @gc_interval >= @last_gc_time
124124
prune_pool
125-
grow_pool
126125
@last_gc_time = Time.now.to_f
127126
end
127+
grow_pool
128128
true
129129
end
130130
end
@@ -216,7 +216,10 @@ def grow_pool # :nodoc:
216216
else
217217
additional = 0
218218
end
219-
additional.times{ @pool << create_worker_thread }
219+
additional.times do
220+
break if @pool.length >= @max_length
221+
@pool << create_worker_thread
222+
end
220223
@largest_length = [@largest_length, @pool.length].max
221224
end
222225

spec/concurrent/cached_thread_pool_shared.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131

132132
context 'worker creation and caching' do
133133

134-
subject{ described_class.new(idletime: 1, max_threads: 5, gc_interval: 0) }
134+
subject{ described_class.new(idletime: 1, max_threads: 5) }
135135

136136
it 'creates new workers when there are none available' do
137137
subject.length.should eq 0
@@ -151,7 +151,7 @@
151151

152152
it 'never creates more than :max_threads threads' do
153153
pool = described_class.new(max_threads: 5)
154-
100.times{ sleep(0.01); pool << proc{ sleep(1) } }
154+
100.times{ pool << proc{ sleep(1) } }
155155
sleep(0.1)
156156
pool.length.should eq 5
157157
pool.kill

0 commit comments

Comments
 (0)