Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSI 400/500 Operating Systems Spring 2009 Lecture #16 – Synchronization with Monitors Wednesday, April 1 st.

Similar presentations


Presentation on theme: "CSI 400/500 Operating Systems Spring 2009 Lecture #16 – Synchronization with Monitors Wednesday, April 1 st."— Presentation transcript:

1 CSI 400/500 Operating Systems Spring 2009 Lecture #16 – Synchronization with Monitors Wednesday, April 1 st

2 2 Multiple Synchronization  In modern operating systems, processes may share a set of resources.  Each resource requires a semaphore  Overhead gets overwhelming

3 3 AND Synchronization  Early attempts used a Wait function with multiple parameters  Obtained all resources at once  Required 2 nd process to enqueue all resources

4 4 Event  Discrete operating system entity  Has unique id and descriptor like thread  Performs operating system activities  Accessed via function calls

5 5 Synchronization Event  Used for multiple resource synchronization  3 functions: Wait()Wait() Signal()Signal() Queue()Queue()

6 6 Monitors  Self-contained multiple resource synchronization event  Object containing storage, procedures, interface, and queues  Only one process can “enter” monitor at a time  Can access any data or function in monitor

7 7 Condition Variables  A variable on a crucial data area  Allows a process or thread to relinquish the monitor if it requires a resource elsewhere  Conditional variable has a queue

8 8 Sample Monitor Data area Conditional variable queues Library of functions

9 9 Interprocess Communication  Used by monitors to communicate among threads on their conditional variable queues Necessary if data changesNecessary if data changes

10 10 IPC types  Pipes Traditional UNIX methodTraditional UNIX method FIFO buffer at kernel levelFIFO buffer at kernel level Write() and read()Write() and read()  Message Passing Used by most OS and used by monitorsUsed by most OS and used by monitors Monitor contains mailboxMonitor contains mailbox Send() and receive()Send() and receive()

11 11 Example #1 – Traffic signals  Think of one-lane crossing  Only allows one direction flow  Light changes if all cars pass or a timer goes off  Lights are traffic controlled, so cars don’t wait if no traffic in other direction

12 12 Monitor – Example #1  Enter monitor – one arrival() for each direction  Depart(direction)  Internal function switch()  Data is count of cars in each direction, RED/GREEN signals in each direction, and timer  Code seen on p 350

13 13 Example #2 – Dining Philosophers  5 place settings, bowl of spaghetti in middle  One fork per place setting  Philosopher requires two forks to eat

14 14 Monitor – Example #2  Each philosopher has state: thinking, hungry, eating  Counter of forks in action  PickupFork(p) – Philosopher p picks up fork If 1 st, sets state to hungryIf 1 st, sets state to hungry If 2 nd, sets state to eatingIf 2 nd, sets state to eating  Finish(p) – releases fork and sets state to thinking  Code on pg 351


Download ppt "CSI 400/500 Operating Systems Spring 2009 Lecture #16 – Synchronization with Monitors Wednesday, April 1 st."

Similar presentations


Ads by Google