首页 > 其他 > 详细

【SICP练习】114 练习3.38

时间:2015-03-26 14:48:40      阅读:232      评论:0      收藏:0      [点我收藏+]

练习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.

分析

a小题中题目假定银行系统强迫着三个进程按照某种顺序方式进行。将3个人(或者说3个进程)全排序有A(3,3)=3X2X1=6种方式。具体为:
Peter (110) -> Paul (90) -> Mary (45)
Peter (110) -> Mary (55) -> Paul (35)
Paul (80) -> Peter (90) -> Mary (45)
Paul (80) -> Mary (40) -> Peter (50)
Mary (50) -> Peter (60) -> Paul (40)
Mary (50) -> Paul (30) -> Peter (40)

b小题参照书中第209页即可,由于编辑较困难在此就不予列出了。

【SICP练习】114 练习3.38

原文:http://blog.csdn.net/nomasp/article/details/44649665

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!