psimjava
Class Csemaphore

java.lang.Object
  extended by psimjava.Csemaphore

public class Csemaphore
extends java.lang.Object

PsimJ Java package for OO simulation

Object-oriented simulation package, process interaction approach.

(C) J. M. Garrido. June 2000 Rev.2003, 2004, Oct. 2007 Counting semaphore class.

File: Csemaphore.java


Constructor Summary
Csemaphore(java.lang.String name, int initval)
          Constructor for the counting semaphore object
 
Method Summary
 void csignal()
          This method increments the semaphore object Then the method reactivates and removes from the semaphore queue any waiting processes.
 void cwait()
          This method allows the requesting process to decrement the semaphore if possible.
 java.lang.String get_name()
          This method returns the name of the semaphore object
 int length()
          This method gets the number of waiting processes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Csemaphore

public Csemaphore(java.lang.String name,
                  int initval)
Constructor for the counting semaphore object

Parameters:
name - the title for the semaphore object
initval - the initial value of csem attribute
Method Detail

get_name

public java.lang.String get_name()
This method returns the name of the semaphore object


cwait

public void cwait()
This method allows the requesting process to decrement the semaphore if possible. The requesting process is suspended and placed in the semaphore queue, if it cannot immediately decrement the semaphore.


length

public int length()
This method gets the number of waiting processes.

Returns:
int Number of Waiting processes

csignal

public void csignal()
This method increments the semaphore object Then the method reactivates and removes from the semaphore queue any waiting processes.