Class: ThreadPool

Inherits:
Object
  • Object
show all
Defined in:
lib/org_lang_stats/thread_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(threads) ⇒ ThreadPool

Returns a new instance of ThreadPool.



5
6
7
8
9
# File 'lib/org_lang_stats/thread_pool.rb', line 5

def initialize(threads)
    @pool = Queue.new
    threads.times { @pool << 1 }
    @workers = []
end

Instance Method Details

#join_workersObject



19
20
21
# File 'lib/org_lang_stats/thread_pool.rb', line 19

def join_workers
    @workers.map(&:join)
end

#run(&block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/org_lang_stats/thread_pool.rb', line 11

def run(&block)
    @pool.pop
    @workers << Thread.new do
        block[]
        @pool << 1
    end
end