sicp-ex-3.45



<< Previous exercise (3.44) | Index | Next exercise (3.46) >>


xdavidliu

The correct implementation of serialized-exchange in the book deliberately leaves the dispatched withdraw and deposit procedures *un*-serialized, so that when the "raw" exchange procedure calls them and then gets wrapped, via serialized-exchange, in the serializers of both accounts involved in the exchange, there will be no conflict.

Louis' proposed change would be disastrous because the dispatched withdraw and deposit procedures called in the "raw" exchange procedure would *already* have serializers, so when serialized-exchange wraps the raw exchange in both serializers *again*, it wouldn't even be possible to perform the required withdraws and deposits, *by definition*, since two procedures can be run concurrently if and only if they have *not* been serialized with the same serializer.


erben

Using Louis's code, in exchanging two accounts we will use the same serializer for two times. One in the serialized-exchange function and the other in the dispatch function. According to the implementation of the serializer, if a process has already acquired a mutex and it wants to acquire that mutex again, the busy waiting will never halt.