Concurrent Programming, HW 4
Program PlusMinus. We have six variables X1, X2, X3, X4, Ctrl, and Sum in shared memory. They all have initial values zero. We have five 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.
- [2 hwp] Write a semaphore version of BACI program PlusMinus, that protects critical sections properly.
Use BACI semaphores in your code.
How do you know that your program is correct? Explain.- Make a program version that does not protect critical sections properly. How do you know?
- Make a program version that protects critical sections properly. How do you know? Explain.
- 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. - Would it be useful to have 10 computing processes? Why?
What would be the upper limit for useful number of computing processes? Why?
- Road crossing
- Show that the four conditions for deadlock are fulfilled in the road crossing example (see Fig. 6.1 [Stall05], or lesson 5 slide 8).
- For each condition, give an example on how one migyht prevent it from happening. Try to make the examples such that only one condition is not met, but the others can still be met.
- Look at the example on how to avoid deadlock with Banker's algorithm (see Fig. 16.11 [Bacon93], or lesson 5 slides 44-45)
- Process P2 requests resource R5 which is available. Can the request be granted without danger for deadlock?
- Process P4 requests resource R5 which is available. Can the request be granted without danger for deadlock?
- We have the following subroutines and their operations need to be synchronized:
- When subroutine PrintOut (Pr, Db, ...) is running, no one else can use printer Pr or database Db.
- When subroutine Update (Db, ...) is running, no one else can use database Db.
- When subroutine Combine (Db1, Db2, Db3, ...) is running, no one else can use databases Db1, Db2, or Db3.
Implement the synchronization with semaphores, when actual databases are Payroll, Personnel, Customers and Inventory.
- Explain, why your solution meet the requiremets stated above.
- Explain, how mutual exclusion is implemented.
- Explain, why your solution does not lead to a deadlock.
- Explain, why your solution does not lead to starvation.
- Explain, why the problem setup is unrealistic. Give at least two reasons.
Teemu Kerola 27.11.2009 12:44