Class: Thread::Task::Pool
- Inherits:
-
Object
- Object
- Thread::Task::Pool
- Defined in:
- lib/thread/task/base.rb
Instance Attribute Summary collapse
-
#rest ⇒ Object
readonly
Returns the value of attribute rest.
Instance Method Summary collapse
- #acquire ⇒ Object
-
#initialize(size) ⇒ Pool
constructor
A new instance of Pool.
- #release ⇒ Object
Constructor Details
#initialize(size) ⇒ Pool
Returns a new instance of Pool.
9 10 11 12 13 |
# File 'lib/thread/task/base.rb', line 9 def initialize( size ) @rest = size @monitor = Monitor.new @lock_cond = @monitor.new_cond end |
Instance Attribute Details
#rest ⇒ Object (readonly)
Returns the value of attribute rest.
7 8 9 |
# File 'lib/thread/task/base.rb', line 7 def rest @rest end |
Instance Method Details
#acquire ⇒ Object
15 16 17 18 19 20 |
# File 'lib/thread/task/base.rb', line 15 def acquire @monitor.synchronize do @lock_cond.wait_while{ @rest == 0 } @rest -= 1 end end |
#release ⇒ Object
22 23 24 25 26 27 |
# File 'lib/thread/task/base.rb', line 22 def release @monitor.synchronize do @rest += 1 @lock_cond.signal end end |