This method uses a single thread, which is executing in a monitor, to release threads waiting on condition variable CV, where n is sufficiently large so that all blocked threads are released.for (i = 0; i < n; i++) CV.Signal();
The second method just releases one thread, and allows the released thread to release other threads. This is referred to as cascading signals.
Analyze and compare these methods under Hoare type and Mesa type monitors.// place where threads block CV.Wait(); CV.Signal(); // this one is released and release the next one // other work in a monitor CV.Signal(); // initialize a cascading release here
Suppose we have processes P1 and P2 as follows:monitor deadlock condition p, q; void stop(void) { p.wait; ...... q.signal; } void go(void); { ...... p.signal; q.wait; } // no initialization is required }
The intention of this monitor is that P1 is required to wait on condition p until P2 has completed some task, at which point it calls deadlock.go to release P1. P2 then waits until P1 has performed its task, when it signals condition q to indicate that P2 may continue.P1: repeat ..... deadlock.stop; ..... until false; P2: repeat ..... deadlock.go; ..... until false;
This program looks correct and seems can perform the indicated task. But, it has the potential to deadlock. Find this deadlock. Would the deadlock still be there is the monitor is a Mesa type?
We do not collect your practice work; but, similar problems will appear in quizzes and exams in the future. Note that I will not make any announcement in class for these short quizzes. In other word, short quizzes may take place at any time as long as I see it is appropriate. |