Concurrent programming, exam 14.6.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 2 cu 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. Give a code level example on a critical section. Give a scenario (relating to your example situation), where computation result is erroneous if critical section is not protected properly.
    2. Explain, why the computation result in that same scenario is correct when critical section is protected. Why is the result now correct in all possible scenarios?
    3. Which critical section protection method would be good for this situation? Why this method and not one of the two other methods that you know of? Explain. Show how critical section protection is implemented at pseudo code level in this case.

  2. [9 p] Deadlocks.
    1. [2 p] What is the deadlock problem? Give a concrete (pseudocode) example on deadlock.
    2. [3 p] How can deadlock be detected? What does one do, if deadlock is found?
    3. [2 p] Explain the main principles of Banker's algorithm to prevent deadlocks from occurring. How would it work in your example in part (a)?
    4. [2 p] Give some other concrete method than Banker's algorithm to prevent deadlocks from occurring. What principle is the solution based on? How would it work in your example in part (a).
       
  3. [9 p] Semaphors and Monitor.
    1. How is critical section problem solved in monitor? How does the solution differ from critical section solution with semaphors?
    2. How is synchronization problem solved in monitor? How does the solution differ from critical section solution with semaphors?
    3. Explain the concept "monitor signalling semantics". How does if affect (i) monitor implementation, and (ii) implementation of the routine calling the monitr?

  4. [9 p] Producer-Consumer problem with semafors. There are one each. Buffer size is infinite
    1. [2 p] Describe the problem. Especially explain, what synchronization and communication problems are involved.
    2. [2 p] What does "infinitely large" buffer mean in practice, and how is it implemented in practice? How does this "infinitely large" buffer affect the solution logic (as compared to finite buffer case)?
    3. [5 p] Give a solution using semafors. Present the pseudocode for producer and consumer. Declare clearly all your semafores and other data structures with their initial values. Explain why your solution is correct.