Dai concetti del sistema operativo di Abraham Silberschatz, Peter B. Galvin, Greg Gagne
5.8.3 Implementing a Monitor Using Semaphores
We now consider a possible implementation of the monitor mechanism using semaphores. For each monitor, a semaphore
mutex(initialized to 1) is provided. A process must executewait(mutex)before entering the monitor and must executesignal(mutex)after leaving the monitor.Since a signaling process must wait until the resumed process either leaves or waits, an additional semaphore,
next, is introduced, initialized to 0. The signaling processes can usenextto suspend themselves. An integer variablenext countis also provided to count the number of processes suspended onnext. Thus, each external functionFis replaced bywait(mutex); ... body of F ... if (next count > 0) signal(next); else signal(mutex);Mutual exclusion within a monitor is ensured.
-
Poiché il semaforo
mutexè inizializzato a 1, è usato per limitare al massimo un processo può essere all'interno del monitor? -
Il semaforo
nextindica il numero di processi sospesi sunext. Questi processi sono sospesi sunextall'interno di un monitor? -
Se le risposte alle due domande precedenti sono sì, si contraddicono a vicenda?
Se no, come funziona realmente un monitor?
Grazie.