13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

280 Concurrency Chapter 8time, a restriction that violates the spirit of the problem. Therefore, Read must not be aguard procedure but rather a procedure external to the monitor. Proper use of Readwould call the guard procedures StartRead and EndRead around calls to Read, but thereis no assurance that a reader will follow these rules. Monitors therefore fail to protect theshared data adequately.2.10 Crowd monitorsOne nice extension to monitors to avoid this last problem is called crowd monitors.Crowd monitors distinguish guard procedures from ordinary procedures within the monitor.Only guard procedures are mutually exclusive. Ordinary procedures may beinvoked only by activities that have permission to do so; this permission is granted andrevoked by guard procedures. A skeleton of the crowd-monitor solution to the readerswritersproblem is as follows:1 crowd monitor ReadWrite;23 export StartRead, EndRead, Read, StartWrite, EndWrite,4 Write;5 var6 Readers : crowd Read;7 Writers : crowd Read, Write;89 guard procedure StartRead;10 begin11 ... { block the caller until reading is safe }12 enter Readers;13 ...14 end StartRead;1516 guard procedure EndRead;17 begin18 leave Readers;19 ... { bookkeeping, maybe signal a waiting writer }20 end EndRead;2122 guard procedure StartWrite;23 begin24 ... { block the caller until writing is safe }25 enter Writers;26 ...27 end StartWrite;2829 guard procedure EndWrite;30 begin31 leave Writers;32 ... { bookkeeping, maybe signal waiter }33 end EndWrite;34

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!