Semaphores
A Semaphore is basically an object that allows Threads to synchronize their
processing paths, with two methods we will denote, for the moment informally, by Wait and Notify. wait() and notify() will be discussed, formally, in a bit.
-
When Wait is executed by a Thread, the Thread is suspended and put into the queue of the Monitor.
-
When Notify is executed by a Thread, we have two possibilities:
-
The queue of the Monitor has no waiting Thread s and the Monitor, essentially, does nothing.
-
The queue has waiting Thread s. In this case one of the waiting threads will
be removed from the queue and resumes its execution. In general, one cannot assume precedence such as the first Thread
in the queue is the first out. The Thread that executes Notify also continues.