Class: Thread::Task::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/thread/task/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#restObject (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

#acquireObject



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

#releaseObject



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