Give all possible values of x that can result from executing
(define x 10)
(parallel-execute (lambda () (set! x (* x x)))
(lambda () (set! x (* x x x))))
Let P1 be the process squaring x and P2 the process cubing x.
There are two types of interleavings, ones where P1 writes first and ones where
P2 writes first.
case: P1 writes first
P2 can read x either 0, 1, 2, or 3 times before the P1 writes. The values for
these interleavings are: 100*100*100, 10*100*100, 10*10*100, 10*10*10.
case: P2 writes first
P1 can read x either 0, 1, or 2 times before P2 writes. The values for these
interleavings are: 1000*1000, 10*1000, 10*10.
All possible values: 10^2, 10^3, 10^4, 10^5, 10^6
Which of these possibilities remain if we instead use serialized procedures?
(define x 10)
(define s (make-serializer))
(parallel-execute (s (lambda () (set! x (* x x))))
(s (lambda () (set! x (* x x x)))))
The only possible value is 10^6.