pt.ua.concurrent
Class Semaphore

java.lang.Object
  extended by pt.ua.concurrent.CObject
      extended by pt.ua.concurrent.Semaphore
All Implemented Interfaces:
InterruptibleAwaitingThreads, SyncCV
Direct Known Subclasses:
BoundedSemaphore

public class Semaphore
extends CObject

A standard counting semaphore class.

This class follows DbC(tm) methodology (Wikipedia). Where possible, contracts are implement with native's Java assert.

Version:
0.5, November 2011
Author:
Miguel Oliveira e Silva (mos@ua.pt)

Constructor Summary
Semaphore()
          Creates a semaphore initialized with a zero counter and registering waiting threads.
Semaphore(int initialCount)
          Creates a semaphore initialized with a given counter and registering waiting threads.
Semaphore(int initialCount, boolean registerAwaitingThreads)
          Creates a semaphore initialized with a given counter.
 
Method Summary
 void aquire()
          Acquires the semaphore.
 void release()
          Releases the semaphore.
 
Methods inherited from class pt.ua.concurrent.CObject
await, await, await, broadcast, interruptWaitingThreads, lockIsMine, registerAwaitingThreads, signal, syncronizedLockIsMine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Semaphore

public Semaphore()
Creates a semaphore initialized with a zero counter and registering waiting threads.


Semaphore

public Semaphore(int initialCount)
Creates a semaphore initialized with a given counter and registering waiting threads.

Precondition:
initialCount >= 0 - non negative counter

Parameters:
initialCount - value

Semaphore

public Semaphore(int initialCount,
                 boolean registerAwaitingThreads)
Creates a semaphore initialized with a given counter.

Precondition:
initialCount >= 0 - non negative counter

Parameters:
initialCount - value
registerAwaitingThreads - if true, threads are registered when waiting
Method Detail

aquire

public void aquire()
Acquires the semaphore.


release

public void release()
Releases the semaphore.