sicp-ex-3.41



<< Previous exercise (3.40) | Index | Next exercise (3.42) >>


meteorgan

  
  
 No, if you get balance in different order with withdraw and deposit, you will get different result. but all they all legal. 

I disagree. I think the answer is yes. Another process could access balance mid-withdraw or mid-deposit and get the wrong info.


It's not wrong info. If a withdraw or deposit isn't finished, then the original balance is still valid. Accessing balance is a single operation, it cannot be interleaved with other procedures. Therefore, we don't need to protect it.


I believe the book uses these two requirements on concurrency:

  • First, it does not require the processes to actually run sequentially, but only to produce results that are the same as if they had run sequentially.
  • Second, there may be more than one possible ``correct'' result produced by a concurrent program, because we require only that the result be the same as for some sequential order.

An "unprotected" access to balance fulfills both requirements so I would say it does not really matter.