Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
656 views
in Technique[技术] by (71.8m points)

concurrency - What is the hidden queue in monitor implementation using semaphores?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...