lib/tins/limited.rb in tins-1.24.1 vs lib/tins/limited.rb in tins-1.25.0
- old
+ new
@@ -7,10 +7,11 @@
@mutex = Mutex.new
@continue = ConditionVariable.new
@maximum = Integer(maximum)
raise ArgumentError, "maximum < 1" if @maximum < 1
@count = 0
+ @tg = ThreadGroup.new
end
# The maximum number of worker threads.
attr_reader :maximum
@@ -19,19 +20,24 @@
@mutex.synchronize do
loop do
if @count < @maximum
@count += 1
Thread.new do
+ @tg.add Thread.current
yield
@mutex.synchronize { @count -= 1 }
@continue.signal
end
return
else
@continue.wait(@mutex)
end
end
end
+ end
+
+ def wait
+ @tg.list.each(&:join)
end
end
end
require 'tins/alias'