org.objectweb.dream.synchro
Interface Semaphore

All Known Implementing Classes:
AbstractSemaphoreQueuedImpl, SemaphoreFIFOImpl, SemaphoreImpl

public interface Semaphore

A counting semaphore component maintains a set of permits. Each acquire() blocks if necessary until a permit is available, and then takes it. Each release adds a permit. A semaphore initialized to 1 can serve as a mutual exclusion lock.

Different implementations of this interface may provide different ordering guarantees (or lack thereof) surrounding which threads will be resumed upon a signal.

Note: Inspired by Doug Lea's Semaphore class.


Field Summary
static String ITF_NAME
          The default name of the Semaphoreinterface.
 
Method Summary
 void acquire()
          Waits until a permit is available, and take one
 boolean attempt(long msecs)
          Waits at most msecs millisconds for a permit.
 long permits()
          Returns the current number of available permits.
 void release()
          Release a permit
 void release(long n)
          Releases N permits.
 

Field Detail

ITF_NAME

static final String ITF_NAME
The default name of the Semaphoreinterface.

See Also:
Constant Field Values
Method Detail

acquire

void acquire()
             throws InterruptedException
Waits until a permit is available, and take one

Throws:
InterruptedException - if the thread is interrupted while trying to acquire the permit.

attempt

boolean attempt(long msecs)
                throws InterruptedException
Waits at most msecs millisconds for a permit.

Parameters:
msecs - the number of milleseconds to wait. An argument less than or equal to zero means not to wait at all. However, this may still require access to a synchronization lock, which can impose unbounded delay if there is a lot of contention among threads.
Returns:
true if acquired.
Throws:
InterruptedException - if the thread is interrupted while waiting for the permit.

permits

long permits()
Returns the current number of available permits.

Returns:
an accurate, but possibly unstable value, that may change immediately after returning.

release

void release()
Release a permit


release

void release(long n)
             throws IllegalArgumentException
Releases N permits.

Parameters:
n - the number of permits to be released.
Throws:
IllegalArgumentException - if n is negative.


Copyright © 2003, 2005 - INRIA Rhone-Alpes - All Rights Reserved.