Agent System POND 1.2 (28.2.2002)

FIM.synchronisation
Class Semaphor

java.lang.Object
  |
  +--FIM.synchronisation.Semaphor

public final class Semaphor
extends Object

A standard semaphor as defined in books on operating systems. Negative values are the number of threads waiting, positive values the number of possible waits without blocking.
Because of a collision with java.lang.Object, the methods are all prefixed with "Sem": SemWait, SemSignal, SemValue.

Version:
1.0, 1.7.2000
Author:
Michael Sonntag
See Also:
Thread

Constructor Summary
Semaphor()
          Create a new semaphor with a count of 1.
Semaphor(long init)
          Create a new semaphor with the provided count.
 
Method Summary
 void SemInit(long init)
          Re-Initializes the semaphor with the value provided.
 void SemSignal()
          Send a signal to the Semaphor.
 long SemValue()
          Returns the current value of the semaphor.
 void SemWait()
          Waits till the Semaphor is available.
 void SemWaitNoInterrupt()
          Waits till the Semaphor is available.
ATTENTION: Will ignore any interrupts (no interrupt possible; swallows the InterruptedException) and wait again till finally a SemSignal is done.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Semaphor

public Semaphor()
Create a new semaphor with a count of 1.

Semaphor

public Semaphor(long init)
Create a new semaphor with the provided count.
Parameters:
init - initial value of the semaphor
Method Detail

SemInit

public void SemInit(long init)
Re-Initializes the semaphor with the value provided. Take care, strange results may happen if this change is not expected by all other threads (and they are progammed for this)! If threads are waiting and the parameter is greater than their number, the according number of them is set free immediately. If the parameter is less than the number of waiting threads, the waiting threads are set free with the first SemSignals and the excess value is only required for new SemWaits to not block.
Parameters:
init - the value to initialize the semaphor with

SemValue

public long SemValue()
Returns the current value of the semaphor. Three ranges are possible:
Returns:
current value

SemWait

public void SemWait()
             throws InterruptedException
Waits till the Semaphor is available.
Throws:
InterruptedException - if interrupt is called
See Also:
Thread

SemWaitNoInterrupt

public void SemWaitNoInterrupt()
Waits till the Semaphor is available.
ATTENTION: Will ignore any interrupts (no interrupt possible; swallows the InterruptedException) and wait again till finally a SemSignal is done. No termination in between possible!
See Also:
Thread

SemSignal

public void SemSignal()
Send a signal to the Semaphor. If threads are waiting, one of them is started. Which one is NOT defined.

Agent System POND 1.2 (28.2.2002)

Submit a bug

Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.