Concurrent programming, exam 25.1.2013            suomeksiToisella puolella suomeksi  

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.

  1. [9 p] Critical section. 
    1. [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.
    2. [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.
    3. [1 p] When would it be good to protect the critical section with busy wait? Why?
    4. [1 p] When would it be good to protect the critical section with a semaphore? Why?
    5. [1 p] When would it be good to protect the critical section with Ricart-Agrawala token based algorithm? Why?

  2. [9 p] Deadlocks.
    1. [2 p] What is the deadlock problem? Give a concrete example, based on the Dining Philosophers problem.
    2. [4 p] Which four conditions must be in effect for deadlock to occur? Show that they exist in your example in part (a).
    3. [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.
       
  3. [9 p] Monitor.
    1. [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. [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. [3 p] How do monitor condition variables and operations on them differ from semafors and operations on them?
    4. [2 p] Explain the concept "monitor signalling semantics". In which way do you have to consider it when implementing a monitor?

  4. [9 p] Producer-Consumer problem with semafors. There are many producers and consumers. Buffer size is N.
    1. [3 p] Describe the problem. Especially explain, what synchronization and communication problems are involved.
    2. [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.