13.07.2015 Views

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

An Operating Systems Vade Mecum

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

292 Concurrency Chapter 86. Prove that Dekker’s non-alternating switch makes it impossible for an activity tostarve while it is waiting to enter its region, on the assumption that whenever theconflicting activity enters its region, it eventually leaves that region.7. Generalize Dekker’s non-alternating switch to three conflicting activities. (somewhatdifficult)8. Generalize Dekker’s non-alternating switch to n conflicting activities. (difficult)9. Prove that Peterson’s non-alternating switch cannot starve either activity.10. Prove that Peterson’s non-alternating switch guarantees mutual exclusion.11. Generalize Peterson’s non-alternating switch to n conflicting activities. (hard)12. Instead of test-and-set, some computers provide an atomic instruction that sets thenew value to 1 greater than its old value, as shown here:1 atomic function Test<strong>An</strong>dInc(var Lock : integer) : integer;2 begin3 Test<strong>An</strong>dInc := Lock;4 Lock := Lock + 1;5 end Test<strong>An</strong>dInc;Show how to use this instruction to implement locks. (Hint: You must be wary ofinteger overflow.)13. The Finishing and WaitFor routines in the text work fine if the entire synchronizationgraph is to be executed just once. Show how to modify them so that if wewish to run the entire graph again, the Done variables have the correct values.14. What does a cycle in a synchronization graph mean?15. Procedures Finishing and WaitFor associate with every activity a Done variablethat is set when the activity finishes. <strong>An</strong> alternative is to associate a Start variablewith every activity and have the activity check it before it starts. Show how thesynchronization graph of Figure 8.1 could be implemented in this way.16. Show how to use semaphores to implement the synchronization graph so that eachsemaphore is associated with an activity and the activity waits (perhaps a numberof times) for its own semaphore before starting.17. We claim that a compiler can check for conflicting orders of nesting in regionstatements. Exactly how can the compiler accomplish this task?18. Show why critical regions cannot implement the synchronization graph of Figure8.1 without busy waiting.19. Write a solution to the readers-writers problem using conditional critical regions,making sure that readers and writers never starve. All you need to provide is StartRead,EndRead, StartWrite, and EndWrite. (Hint: Separate readers into platoons.The next one starts filling as soon as a writer arrives. Alternate a platoon ofreaders with a single writer.)20. Write a monitor solution to the readers-writers problem. (See the discussion forexercise 19.)

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

Saved successfully!

Ooh no, something went wrong!