1 / 5

Monitor Semaphore: Wait and Signal

Monitor Semaphore is a synchronization primitive that allows processes to wait and signal each other. The behavior of wait and signal operations depends on the state of the semaphore. This implementation ensures mutual exclusion and proper handling of waiting processes.

ebernard
Download Presentation

Monitor Semaphore: Wait and Signal

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Monitor Implementation x Condition variables and their queues y Entry queue Entry procedures Initialization code POS-A

  3. 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 POS-A

  4. 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. POS-A

  5. 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 POS-A

More Related