Yliopiston etusivulle Suomeksi På svenska In English
Helsingin yliopisto Tietojenkäsittelytieteen laitos
 

Tietojenkäsittelytieteen laitos

Suomeksi In English Homework

Concurrent Programming, HW 3

  1. Look at Dekker algorithm (alg 3.10, p.60). At the end of the algorithm variables turn and wantp (or wantq) are given new values. Could one also give them in reverse order (statement p10 before p9)? Prove your conclusions.
     
  2. Exercises 3.11 and 3.12 from text book
     
  3. Exercise 4.1 from text book
     
  4. Exercises 5.1 and 5.3 from text book.
     
  5. [2 hwp] Program PlusMinus. We have six variables X1, X2, X3, X4, Ctrl, and Sum in shared memory. They all have initial values zero. We have two computing processes, each of which will execute a loop 50 times. The critical section in the loop does the following:
    • If variable value Ctrl is odd, subtract 1 from each Xi. Otherwise, add 2 to each Xi.
    • Finally add 1 to Ctrl and store the sum of all Xi's into Sum.
    Once the computing processes have stopped, print out the values of all six shared variables (50, 50, 50, 50, 100 ja 200).

    Implement this program in BACI, using only (other) shared variables for control. Possible waitings can be implemented with busy-wait type loops: while (...) {};
    BACI process control will always finally yield execution turn to other processes, i.e., waiting is not for ever.
    1. Make a program version that does not protect critical sections properly. How do you know?
    2. Make a program version that protects critical sections properly. How do you know? Explain.
    3. How would your program need to be modified for 4 or 10 computing processes?
      Note, that you do not need to implement the suggested modification in BACI. But, you can try to do it anyway, if you want to.
    4. Would it be useful to have 10 computing processes? Why?
      What would be the upper limit for useful number of computing processes? Why?
       

Teemu Kerola