WaitSignal in Monitor Semaphore Always suspends Changes semaphores

  • Slides: 5
Download presentation
Wait/Signal in Monitor Semaphore Always suspends Changes semaphore’s state Suspends or not depends on

Wait/Signal in Monitor Semaphore Always suspends Changes semaphore’s state Suspends or not depends on state Resumes a waiting process = No-op if no process waiting Resumes a waiting process Changes semaphore’s state Wait Signal • To avoid confusions, some texts stick to using P and V for semaphore’s wait and signal. 4/11/1999 POS-A 1

Monitor Implementation Condition variables and their queues x y Entry queue Entry procedures Initialization

Monitor Implementation Condition variables and their queues x y Entry queue Entry procedures Initialization code 4/11/1999 POS-A 2

Two Choices • Suppose a process (W) is waiting on x. • Another process

Two Choices • Suppose a process (W) is waiting on x. • Another process (S) then executes x. signal. • Should we suspend S and let W run? – Yes the implementation we saw – No (S continues to execute) danger is that the logical condition for which W was waiting may no longer hold 4/11/1999 POS-A 3

Guarantees • Execution of procedures must be mutually exclusive. • A wait must block

Guarantees • Execution of procedures must be mutually exclusive. • A wait must block the current process on the corresponding condition. • When a process exits or is blocked on a condition and there are processes waiting to enter or reenter the monitor, one must be selected. – If there is a process suspended as the result of executing a signal operation, then it is selected; otherwise, one of the processes from the initial queue of entering processes is selected (processes blocked on conditions remain suspended) • A signal must determine if any process is waiting on the corresponding condition. If this is the case, the current process is suspended and one of these waiting processes is reactivated; otherwise, the current process continues. 4/11/1999 POS-A 4

The Implementation mutex a semaphore initialized to 1; used to guard mutual access to

The Implementation mutex a semaphore initialized to 1; used to guard mutual access to procedures inside the monitor next a semaphore initialized to 0; used to suspend a process when executing a signal operation (the Yes choice) x-sem a semaphore initialized to 0; used to suspend a process executing a wait on x next-count preset to 0; contains the number of processes suspended as a result of a signal operation x-count preset to 0; contains the number of processes suspended as a result of a wait operation on x 4/11/1999 POS-A 5