Concurrent programming, exam 25.9.2012            suomeksiToisella puolella suomeksi  

This course is worth 6 cu, if you have done the project, and o/w 4 cu.
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. Explain, why the computation result in that same scenario is correct when critical section is protected.
    2. Which critical section protection method would be good for this situation? Why this method and not some two other methods that you know of? Explain. Show how critical section protection is implemented at code level in this case.

  2. [9 p] Deadlocks. Application App with 4 threads (P, R, S and T) is using three resources (A, B and C) and that can sometimes lead to a deadlock. There is one unit of each resource and each resourse may be used by only one thread at a time.
    1. [4 p] Explain the deadlock problem. Give a scenario leading to a deadlock in application App. Present the scenario with appropriate pseudocode for deadlocking processes.
    2. [2 p] Give a concrete (real) resource for each resource A, B and C. Use at least two different types of resources.
    3. [3 p] Which four conditions must be in effect for deadlock to occur? Show that they exist in your scenario in part (a) with the concrete resources (A, B, and C) given in part (b).
       
  3. [9 p] Semaphores. Processes P and Q can execute computational phase A only after process R has reached certain point t in its execution. Process R can proceed its own execution after point t only after processes R and Q have completed phase A.
    1. [6 p] Solve this synchronization problem with semaphores. Give the pseudocode for P, Q, and R. Explain the meaning of all your semaphores and give their initial values.
    2. [3 p] Assume now, that the synchronization problem bethween processes P, Q, and R repeats many times during the same execution. If needed, modify your solution for part (a) so that it can handle also this situation. Explain, why your synchronization problem solution works out correctly in successive turns that it is used.

  4. [9 p] Monitor.
    1. [2 p] How does a monitor solve critical section problem? Where does critical section begin and where does it end?
    2. [3 p] How does a monitor solve synchronization problem? How does it differ from using semaphores?
    3. [2 p] In which different places in the monitor may the processes executing there may need to wait for their execution turn?
    4. [2 p] What does the concept monitor signalling semantics mean? Give an code example of a situation where the code works with IRR-semantics, but not with signal-and-continue semantics.