This course is worth 6 cu, if you have done the 2 cu project, and otherwise 4 cu.
If you have done the project with a lecture course, please mention about it and give the year.
Write in each answer sheet course name, date, your name, signature and student id.
- [9 p] Critical section.
- [3 p] Give a code level example on a critical section with just one code segment. Give a scenario (relating to your example situation), where computation result is erroneous if critical section is not protected properly. Explain, why the computation result in that same scenario is correct when critical section is protected.
- [3 p] Give a code level example on a critical section with two code segment. Give a scenario (relating to your example situation with two code segments), where computation result is erroneous if critical section is not protected properly. Explain, why the computation result in that same scenario is correct when critical section is protected.
- [1 p] When would it be good to protect the critical section with busy wait? Why?
- [1 p] When would it be good to protect the critical section with a semaphore? Why?
- [1 p] When would it be good to protect the critical section with Ricart-Agrawala token based algorithm? Why?
- [9 p] Deadlocks.
- [2 p] What is the deadlock problem? Give a concrete example, based on the Dining Philosophers problem.
- [4 p] Which four conditions must be in effect for deadlock to occur? Show that they exist in your example in part (a).
- [3 p] Based on previous four conditions (part b), give three different methods to prevent deadlock in advance with Dining Philosophers Problem. Explain, why and how each method works to prevent deadlock in this case.
- [9 p] Monitor.
- [2 p] What is a monitor? To what problem is monitor solution for? How does the use of monitors relate to use of semafors?
- [2 p] How does a monitor solve the critical section problem? In what parts of the monitor code does critical section begin and end?
- [3 p] How do monitor condition variables and operations on them differ from semafors and operations on them?
- [2 p] Explain the concept "monitor signalling semantics". In which way do you have to consider it when implementing a monitor?
- [9 p] Producer-Consumer problem with semafors. There are many producers and consumers. Buffer size is N.
- [3 p] Describe the problem. Especially explain, what synchronization and communication problems are involved.
- [6 p] Give a solution using semafors. Present the pseudocode for producers and consumers. Declare clearly all your semafores with their initial values. Explain why your solution is correct.