Method: Zold::ThreadPool#add

Defined in:
lib/zold/thread_pool.rb

#addObject

Add a new thread



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/zold/thread_pool.rb', line 70

def add
  raise 'Block must be given to start()' unless block_given?
  latch = Concurrent::CountDownLatch.new(1)
  thread = Thread.start do
    Thread.current.name = @title
    VerboseThread.new(@log).run do
      latch.count_down
      yield
    end
  end
  latch.wait
  Thread.current.thread_variable_set(
    :kids,
    (Thread.current.thread_variable_get(:kids) || []) + [thread]
  )
  @threads << thread
end