lib/thread/pool.rb in thread-0.1.5 vs lib/thread/pool.rb in thread-0.1.6

- old
+ new

@@ -189,24 +189,30 @@ } end # Are all tasks consumed ? def done? - @todo.empty? and @waiting == @spawned + @mutex.synchronize { + @todo.empty? and @waiting == @spawned + } end # Wait until all tasks are consumed. The caller will be blocked until then. def wait_done - @done_mutex.synchronize { - return if done? - @done.wait @done_mutex - } + loop do + @done_mutex.synchronize { + return self if done? + @done.wait @done_mutex + } + end end # Check if there are idle workers. def idle? - @todo.length < @waiting + @mutex.synchronize { + @todo.length < @waiting + } end # Process Block when there is a idle worker if not block its returns def idle (*args, &block) while !idle? @@ -219,10 +225,9 @@ unless block return end process *args, &block - end # Add a task to the pool which will execute the block with the given # argument. #