Exercise 3.43. Suppose that the balances in three accounts start out as $10, $20, and $30, and that multiple processes run, exchanging the balances in the accounts. Argue that if the processes are run sequentially, after any number of concurrent exchanges, the account balances should be $10, $20, and $30 in some order. Draw a timing diagram like the one in figure 3.29 to show how this condition can be violated if the exchanges are implemented using the first version of the account-exchange program in this section. On the other hand, argue that even with this exchange program, the sum of the balances in the accounts will be preserved. Draw a timing diagram to show how even this condition would be violated if we did not serialize the transactions on individual accounts. ———————————————————————————————————————————————————————————————————————— Each exchange between any two bank accounts, given that the balances before the exchange are, $10, $20, and $30, will only modify either account inside a procedure which is serialized on both accounts. This ensures that no exchange procedure will read or write to the accounts while another is running. Since after each exchange, the account balances are still $10, $20, and $30 in some order, and exchanges are fully sequenced, any number of exchanges will leave the balances at these values. If the first procedure is used as described in the text, on three accounts a1, a2, and a3, it is possible for the following to happen: starting balances: a1: $10 a2: $20 a3: $30 Peter computes a difference between a1 and a2 of $10. Paul then exchanges a1 with a3, so the balance of a1 is now $30. Peter's procedure then completes, transferring $10 from a2 to a1. The closing balances are $40 for a1, and $10 each in the other two accounts. The total balance of all three accounts is preserved, even though there is no sequence of exchanges that would give this result. "Draw a timing diagram to show how even this condition would be violated if we did not serialize the transactions on individual accounts." This is too similar to earlier exercises; skipped.