<< Previous exercise (3.43) | Index | Next exercise (3.45) >>


Exchange requires both accounts to be idle before we start exchanging (i.e. exchanging a with b while a is still exchanging with c is not allowed)

For transfer, there is no such requirement. Louis is wrong.


In the exchange problem, state of one account depends on the state of another account (they are coupled). There is no such coupling in the transfer problem.


Another way to rephrase what sam says is to say that exchange has an unserialized access (the difference process) which can occur concurrently with another exchange underway while transfer has no such process...


Louis is right. There is an issue with Ben's logic. If you run multiple transfers simultaneously between multiple accounts, in Ben's version it is possible that accounts run of money without needing to - failing some transactions. In Louis' version, as the full exchange is serialized, money must enter the account to which its being transferred, before another transfer can be initiated from it. If you have a lot of money, its not a problem (you will eventually be credited). If you have a little money, you might not be so indifferent.

  e.g. A has 10, B 20, C 10
  T1 -> 10 from C to B, 
  T2 -> 30 from B to A
  If T1 and T2 are fully serialized, T2 will proceed. Otherwise while T1 is half completed (10 leaves C) T2 could initiate, and fail. After this B gets the additional 10, but its too late.

Note that if T1 and T2 are initiated simultaneously, using parallel-execute, T2 could still fail if it initiates before T1. But in general, it will still be much better to ensure money that leaves an account enters another account before another transaction is started on the 2nd account. In other words - a transfer should be atomic.