Method: ThreadLimiter#initialize

Defined in:
lib/rwd/thread.rb

#initialize(limit) ⇒ ThreadLimiter

Returns a new instance of ThreadLimiter.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rwd/thread.rb', line 14

def initialize(limit)
  @limit	= limit
  @count	= 0
  @threads	= []
  @mutex	= Mutex.new
  @cv		= ConditionVariable.new

  every(1) do
    @mutex.synchronize do
      @threads.dup.each do |t|
        unless t.alive?
          $stderr.puts "Found dead thread."

          @threads.delete(t)

          @count -= 1

          @cv.signal
        end
      end
    end
  end
end