This class is to implement the function of semaphore.
This class works as an semaphore, it can sleep(P) and wake up (V). When initialize a Semaphore, you can
specify a number which indicates the size of the Semaphore. If the number is 1, it means mutual exclusive.
Variable
value: This variable is to indicate the size of the semaphore. SemaTable : This is a static hash table to store all the semaphores used in this system.
Methods
getSemaphore(String, int) : The string is the key of the semaphore in the SemaTable. If the semaphore already exists, it will return the semaphore. If the semaphore not exists, it will initialize one with the value of the input integer and put it into the SemaTable, then retrive it right after.
getSemaphore(String) : The same as the previous method, except it will initialize a semaphore with the value 0.
P() : To P the semaphore.
V() : To V the semaphore.