a) I list all the orders of the three process, and then determine the value of balance. For simplicity, I use 1, 2, 3 , instead of Peter, Paul, Mary.
123 |
$45 |
132 |
$35 |
213 |
$45 |
231 |
$50 |
312 |
$40 |
321 |
$40 |
b) If the system allows the processes to be interleaved, there are some other values that could be produced, eg. $30, $55, $60, $80, $90, $110. Here I want to show you how to get these values systematicly, I won't draw the digrams.(please refer to http://wqzhang.wordpress.com/2009/07/30/sicp-exercise-3-38/ for digrams).
We need pay attention to the time of access balance and the time of set balance. I will use the following shortcut notations:
Note: the following precedure assume that, there has interleaved parts between the three processess.
- a1: access balance time of Peter.
- a2: access balance time of Paul.
- a3: access balance time of Mary.
- s1: set balance time of Peter.
- s2: set balance time of Paul.
- s3: set balance time of Mary.
(cond ((< (max a1 a2 a3) (min s1 s2 s3))
(cond ((= (max s1 s2 s3) s1) '$110)
((= (max s1 s2 s3) s2) '$80)
((= (max s1 s2 s3) s3) '$50)))
;;If s1 is big than some access time.
((and (> a2 s1) (> a3 s1))
(cond ((> s2 s3) '$90)
((> s3 s2) '$55)))
((and (> a2 s1) (< a3 s1))
(cond ((> s2 s3) '$90)
((> s3 s2) '$50)))
((and (< a2 s1) (> a2 s1))
(cond ((> s2 s3) '$80)
((> s3 s2) '$55)))
;;If s2 is big than some access time.
((and (> a1 s2) (> a3 s2))
(cond ((> s1 s3) '$90)
((> s3 s1) '$40)))
((and (> a1 s2) (< a3 s2))
(cond ((> s1 s3) '$90)
((> s3 s1) '$50)))
((and (< a1 s2) (> a3 s2))
(cond ((> s1 s3) '$110)
((> s3 s1) '$40)))
;;If s3 is big than some access time.
((and (> a1 s3) (> a2 s3))
(cond ((> s1 s2) '$60)
((> s2 s1) '$30)))
((and (> a1 s3) (< a2 s3))
(cond ((> s1 s2) '$60)
((> s2 s1) '$80)))
((and (< a1 s3) (> a2 s3))
(cond ((> s1 s2) '$110)
((> s2 s1) '$30))))