Chinaunix

标题: SICP 习题参考答案 3.4 [打印本页]

作者: win_hate    时间: 2009-01-05 11:44
标题: SICP 习题参考答案 3.4
此帖为 SICP 章节 3.4 的参考答案。为保持可读性,请勿直接在本帖讨论。讨论请另开新帖。




[ 本帖最后由 win_hate 于 2009-1-5 11:45 编辑 ]
作者: win_hate    时间: 2009-01-05 11:46
标题: Exercise 3.38.
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)))

a. 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.

b. 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.
作者: win_hate    时间: 2009-01-05 11:49
标题: Exercise 3.38. 答案