Class: RbEAI::WorkerPool
- Inherits:
-
Object
- Object
- RbEAI::WorkerPool
- Defined in:
- lib/rbeai/WorkerPool.rb
Instance Method Summary collapse
-
#initialize(size, nmessages, inputQueue, resultQueue, method) ⇒ WorkerPool
constructor
A new instance of WorkerPool.
- #run ⇒ Object
- #stop ⇒ Object
- #stopcontrol ⇒ Object
Constructor Details
#initialize(size, nmessages, inputQueue, resultQueue, method) ⇒ WorkerPool
Returns a new instance of WorkerPool.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rbeai/WorkerPool.rb', line 7 def initialize(size, , inputQueue, resultQueue, method) @size = size @inputQueue = inputQueue @resultQueue = resultQueue @controlQueue = Queue.new @control = Thread.new() do |nmess| Thread.stop() print "Running control thread\n" count = 0 begin aux = @controlQueue.deq count = count + 1 end until count == nmess print "Finished control thread\n" stop() end @threadlist = [] size.times do |i| @threadlist << Thread.new(i) do |j| Thread.stop() print "Running th ",j,"\n" begin obj = @inputQueue.deq if obj != :FINISH_WORK method.call(obj, j) @controlQueue.enq(:COUNT) end end until obj == :FINISH_WORK print "Finished th ",j,"\n" end end end |
Instance Method Details
#run ⇒ Object
41 42 43 44 |
# File 'lib/rbeai/WorkerPool.rb', line 41 def run() @control.run @threadlist.each { |t| t.run} end |
#stop ⇒ Object
46 47 48 49 |
# File 'lib/rbeai/WorkerPool.rb', line 46 def stop() @size.times { |i| @inputQueue.enq(:FINISH_WORK) } @threadlist.each { |t| t.join } end |
#stopcontrol ⇒ Object
51 52 53 |
# File 'lib/rbeai/WorkerPool.rb', line 51 def stopcontrol() @control.join end |