You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sicp-all-tasks/sicp/3_002e38

24 lines
799 B

Exercise 3.38: Suppose that Peter, Paul, and
Mary share a joint bank account that initially contains $100. Concurrently,
Peter deposits $10, Paul withdraws $20, and Mary withdraws half the money in
the account, by executing the following commands:
Peter: (set! balance (+ balance 10))
Paul: (set! balance (- balance 20))
Mary: (set! balance (- balance
(/ balance 2)))
List all the different possible values for balance after these three
transactions have been completed, assuming that the banking system forces the
three processes to run sequentially in some order.
What are some other values that could be produced if the system allows the
processes to be interleaved? Draw timing diagrams like the one in Figure 3.29
to explain how these values can occur.