I am trying to solve this question and need some help about monitor implementation using semaphores.
Question: In monitor implementation using semaphores, there are 3 queues. One of these queues is not visible by applications. In the example implementation below, define the type of this invisible queue and explain why it is needed.
Variables
semaphore mutex; // (initially = 1)
semaphore next; // (initially = 0)
int next_count = 0;
Each procedure F will be replaced by
wait(mutex);
…
body of F;
…
if (next_count > 0)
signal(next)
else
signal(mutex);
For each X:
semaphore x-sem; // 0 at start
int x-count = 0; // counts blocked threads
x.wait monitor operation can actualize like that:
x-count++;
if (next-count > 0)
signal(next);
else
signal(mutex);
wait(x-sem);
x-count--;
x.signal monitor operation can actualize like that:
if (x-count > 0) {
next-count++;
signal(x-sem);
wait(next);
next-count--;
}
UPDATE
I've found there are three (semaphore) queues in the implementation:
- The mutex queue, where processes waiting to enter the monitor wait
- The next queue, where processes that are within the monitor and ready, wait to become the active process, and
- The condition queue(s), where a blocked process waits to be signaled.
But still don't know which one is not accessible/visible to other applications.
question from:
https://stackoverflow.com/questions/65871302/what-is-the-hidden-queue-in-monitor-implementation-using-semaphores 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…