Class: Jabber::Semaphore

Class | Jabber::Semaphore
In: | lib/xmpp4r/semaphore.rb
Parent: | Object

This class implements semaphore for threads synchronization.

### Methods

new run wait

### Public Class methods

new(val=0)

Initialize new semaphore

val: | [Integer] number of threads, that can enter to section

[Source]

        # File lib/xmpp4r/semaphore.rb, line 14
    14:     def initialize(val=0)
    15:       @tickets = val
    16:       @lock = Mutex.new
    17:       @cond = ConditionVariable.new
    18:     end

### Public Instance methods

run()

Unlocks guarded section, increments number of free tickets

[Source]

        # File lib/xmpp4r/semaphore.rb, line 31
    31:     def run
    32:       @lock.synchronize {
    33:         @tickets += 1
    34:         @cond.signal
    35:       }
    36:     end

wait()

Waits until are available some free tickets

[Source]

        # File lib/xmpp4r/semaphore.rb, line 22
    22:     def wait
    23:       @lock.synchronize {
    24:         @cond.wait(@lock) while !(@tickets > 0)
    25:         @tickets -= 1
    26:       }
    27:     end

[Validate]