simulator
Class Semaphore

java.lang.Object
  |
  +--simulator.Semaphore

class Semaphore
extends java.lang.Object

This class is a multi-value semaphore with P and V operations that performs a process suspension if there's no other available resorces. The P and V operation use a internal Java mutex to avoid conflicts.


Field Summary
(package private)  int N
          The actual number of process that are suspend
(package private)  java.lang.String O
          This string contain the Owner of the process that call a P or V operation, but it is never used.
(package private)  int value
          The actual number of available resorces
 
Constructor Summary
Semaphore(int initSem, java.lang.String Owner)
          Initialize the semaphore with starting resorces and owner string of process
 
Method Summary
 void P()
          Perform a P operation (if there's no other resorces the process will be suspend)
 void V()
          Perform a V operation (if there's suspended processes, it will resume one of them)
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

value

int value
The actual number of available resorces

N

int N
The actual number of process that are suspend

O

java.lang.String O
This string contain the Owner of the process that call a P or V operation, but it is never used.
Constructor Detail

Semaphore

public Semaphore(int initSem,
                 java.lang.String Owner)
Initialize the semaphore with starting resorces and owner string of process
Parameters:
initSem - the initial resources number
Owner - a string for the owner (actualy never used)
Method Detail

P

public void P()
Perform a P operation (if there's no other resorces the process will be suspend)

V

public void V()
Perform a V operation (if there's suspended processes, it will resume one of them)