GridSim
v3.0

eduni.simjava
Class Semaphore

Object
  extended byeduni.simjava.Semaphore

public class Semaphore
extends Object

A counting semaphore class.

This class is used internally by Sim_system to synchronize the simulation's entities. Semaphores should not be needed in user simulations.

Version:
1.0, 4 September 1996
Author:
Ross McNab
See Also:
Sim_system

Constructor Summary
Semaphore()
          Allocate a new semaphore object with an initial count of zero.
Semaphore(int count)
          Allocates a new semaphore object with a given initial count.
 
Method Summary
 void p()
          Try to obtain the semaphore.
 void v()
          Free the semaphore, by incrementing the internal count.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Semaphore

public Semaphore()
Allocate a new semaphore object with an initial count of zero.


Semaphore

public Semaphore(int count)
Allocates a new semaphore object with a given initial count.

Parameters:
count - The initial count of the semaphore.
Method Detail

p

public void p()
Try to obtain the semaphore. If the count is above zero, the function decrements it, then return so the calling thread can continue. If the count is zero then the calling thread is suspended until it becomes non-zero.


v

public void v()
Free the semaphore, by incrementing the internal count.


GridSim
v3.0

The University of Melbourne, Australia, 2004