Concurrent programming, exam 15.6.2012                      suomeksiToisella puolella suomeksi  

This final exam works also as a make-up exam for one mid-term or end-term exam 2012, which you missed or which did not go so well. Based on this exam, the 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 situation, where critical section is composed of two distinct code segments. Does it differ any any relevant way from th esituation where there is only one code segment? Explain.
    2. Give an example of a situation where it would be wise to protect critical sections with semaphores, but not with busy-wait instructions or interrupt disabling? Explain.
    3. Give an example of a situation where it would be wise to protect critical sections with monitor instead of semaphores? Explain.

     
  2. [9 p] Deadlocks.
    1. Which four conditions must be in effect for deadlock to occur?
    2. Explain the main principles of Dijkstra's deadlock detection algorithm (DDA). What is it needed for? What data and what data structures are needed? When is the algorithm started and when will it terminate? What do you do with the algorithm result?
    3. Explain the main principles of Banker's algorithm. What is it used for? What data and what data structures are needed? When is the algorithm started and when will it terminate? What do you do with the algorithm result?

  3. [9 p] Producer-Consumer problem. There is one producer and one consumer. Buffer size is 1000.
    1. Describe the problem. Especially explain, what synchronization and communication problems are involved. What do you gain with larger buffer?
    2. Give a solution using semafors. Present the pseudocode for producer and consumer. Declare clearly all your semafores with their initial values. Explain why your solution is correct.
    3. Assume now, that we know from the overall system logic that the number of elements in the buffer can never be more than 500. How does this affect the problem solution and the synchronization and communication problems in it. Give the solution using semafors. Present the pseudocode for producer and consumer. Declare clearly all your semafores with their initial values. Explain why your solution is correct.
       
  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.