1 / 11

Lab2: Semaphores and Monitors

Lab2: Semaphores and Monitors. Credits. Material in this slide set is from G. Andrews, “Foundation of Multithreaded, Parallel, and Distributed Programming”, Addison Wesley, 2000. Semaphores. Used for Mutual Exclusion (homework 2) Barriers Signaling events (lab 2) Low level mechanism

troark
Download Presentation

Lab2: Semaphores and Monitors

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. Lab2: Semaphores and Monitors

  2. Credits • Material in this slide set is from G. Andrews, “Foundation of Multithreaded, Parallel, and Distributed Programming”, Addison Wesley, 2000.

  3. Semaphores • Used for • Mutual Exclusion (homework 2) • Barriers • Signaling events (lab 2) • Low level mechanism • Easy to make mistakes • Hard to understand

  4. Monitors • Program modules that provide more structure than semaphores • Abstract objects that are well encapsulate • Only one process or thread can be in the monitor at one time • Use condition variables

  5. Monitors • Active processes • Interact by calling procedure in the same monitor • Passive monitors • Provide methods to manipulate data but no access to internal data structures

  6. Monitors • Benefits • Implementation independent • Only visible effects matter • Callers independent • Monitor writers can change the implementation as long as the same effects are maintained

  7. Monitors • Provide mutual exclusion implicitly • Only one instance of the monitor can be active at one time • 2 calls to two different procedures in the same monitor? NO! • 2 calls to the same procedure in the same monitor? NO!

  8. Monitors • Condition Variables • Delay a process • Monitor’s state fails to satisfy Boolean condition • Awaken a process • Awaken a process or processes if the condition becomes true Is this possible?

  9. Monitors • Signaling Disciplines CV queue SC wait SW Entry queue Executing In monitor Monitor free call return SW From G. Andrews, “Foundation of Multithreaded, Parallel, and Distributed Programming”, Addison Wesley, 2000

  10. Monitors • Signal and continue: signalers continues and the signaled process executes at some later time • Non-preemptive • Signal and wait: signaler waits and the signaled process executes now • Preemptive

  11. Monitors • Signal and Wait in Unix?

More Related