When does a semaphore issue a wait and when does it issue a signal?
-
28-09-2020 - |
Question
In my textbook, Operating Systems: Internals and Design Principles (9th Edition) by William Stallings in chapter 5, it explains how semaphores work:
The fundamental principle is this: Two or more processes can cooperate by means of simple signals, such that a process can be forced to stop at a specified place until it has received a specific signal. Any complex coordination requirement can be satisfied by the appropriate structure of signals. For signaling, special variables called semaphores are used. To transmit a signal via semaphores
, a process executes the primitivesemSignal (s)
. To receive a signal via semaphore s, a process executes the primitivesemWait (s)
; if the corresponding signal has not yet been transmitted, the process is suspended until the transmission takes place.
I can't find a description in chapter 5 of when a semaphore would issue a semSignal vs a semWait (which are also sometimes called signal and wait). Can anyone describe the conditions under which semSignal would be issued vs a semWait?
Solution
The semaphore doesn't issue those. A semaphore is an object that can be used by processes to coordinate between themselves. Thus, a process will call semSignal or semWait on a shared semaphore. We can't describe the conditions under which it will do that in general, because it's up to each process how it wants to use semaphores. Semaphores are a primitive that can be used in many ways. You should be able to find many examples online or in your textbook of using semaphores for coordination; that will give you some examples of specific processes and when those particular processes will invoke those operations on a semaphore.