Class: ParticlePool::Pool
- Inherits:
-
Object
- Object
- ParticlePool::Pool
- Defined in:
- lib/particle_pool/pool.rb
Instance Method Summary collapse
- #<<(t, *args, **kwargs) ⇒ Object
-
#initialize ⇒ Pool
constructor
A new instance of Pool.
- #push(t, *args, **kwargs) ⇒ Object
- #start(size = Etc.nprocessors) ⇒ Object
Constructor Details
#initialize ⇒ Pool
Returns a new instance of Pool.
2 3 4 5 6 7 |
# File 'lib/particle_pool/pool.rb', line 2 def initialize @mtx = Mutex.new @threads = [] @round_robin = false @iter = @threads.each end |
Instance Method Details
#<<(t, *args, **kwargs) ⇒ Object
9 10 11 |
# File 'lib/particle_pool/pool.rb', line 9 def <<(t, *args, **kwargs) push(t, *args, **kwargs) end |
#push(t, *args, **kwargs) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/particle_pool/pool.rb', line 13 def push(t, *args, **kwargs) @mtx.synchronize do thr = @threads.min raise 'no threads available' unless t thr.push(t, *args, **kwargs) end end |
#start(size = Etc.nprocessors) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/particle_pool/pool.rb', line 21 def start(size = Etc.nprocessors) size.times do @threads << ParticlePool::PoolThread.new end @threads.each do |t| Thread.new do t.start end end end |