(Concurrency) 8.0 PQPQ PQ ( )PQ P Q P Q P Q P Q P Q P Q P Q PQ = P Q S S! P Q S P Q x y z x ' = x + 1! y' = y + 2! z' = z x : = x + 1 y : = y + 2 x x y z x : = x + 1 y : = y + 2 = x ' = x + 1! y' = y + 2! z' = z x' x : = x x' x : = x' x : = x x : = y y : = x x y z y y' y : = y x x := yy := x = x' =y y' =x z' = z x y 1
b x b:= x=xx := x+1 = b:= Tx := x+1 Tx=x xx1b x = x x x Tx=x! x' ', y'',... ( x : = x + 1. x : = x! 1) y : = x = ok y : = x = y : = x x x x x ( x : = x + 1. x : = x! 1) ok x x ok x := 3 ok ( x : = x + 1. x : = x! 1) x : = 3 ( x : = x + y. x : = x " y) ( y : = x! y. y : = x / y) x y x y x y ( x : = x + y y : = x " y).( x : = x! y y : = x / y) P Q P Q t P Q P Q PQ = tp, tq (Pt' tp) (Qt' tq) 2
t' = max tp tq 8.0.0 xye, f, b P, Q, RS (x := ey := f). P = (Pxeyf ) PQ = QP P(QR) = (PQ)R Pok = okp = P PQ R = (PQ) (PR) Pif b then Q else R = if b then (PQ) else (PR) if b then (PQ) else (RS) = if b then P else Rif b then Q else S (x := x+yy := x y). z' = x y = z' = (x+y) (x y) A BCB DC E A DE A BCD EF A D B EC F --------------------------------------------------------------------------------------------------------------------------------------------------- 8.0.1 Li : = e = L ' i = e! (% j $ j # i " L' j = Lj)! x' = x! y' = y!... 140MAX MAX LL L L L' 0 = MAX LL0 findmax = λ i, j i<j L' i = MAX L [i;..j] 3
findmax 0 (#L) findmax i j if j i=1 then ok else ( (findmax i (div (i+j) 2)findmax (div (i+j) 2) L i := max (L i) (L (div (i+j) 2)) ) j i = 1i findmax i (div (i+j) 2)findmax (div (i+j) 2) j ceil (log (j i)) j). LLM findmax = λ i, j i<j M' i = MAX L [i;..j] ok M i := L i M i := max (M i) (M (div (i+j) 2)) ------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------------------------------------------------------------------- 8.1 x := y. x := x+1. z := y = x := y. (x := x+1z := y) = (x := y. x := x+1)z := y x := y x := x+1 z := y x := x+1 x := y z := y x := y x := x+1 z := y 4
8.1.0 produceconsumebproduceb consumeb produce =... b := e... consume =... b... control = produce. consume. control PproduceCconsume P C P C P C P C b produce consume b control = produce. newcontrol newcontrol = consume. produce. newcontrol newcontrol newcontrol = ( consume produce ). newcontrol consume b bpc, produce =... p := e... consume =...x:=c... control = produce. newcontrol newcontrol = c := p. ( consume produce ). newcontrol Bc := p P P P P P P P B B B B B B B C C C C C C C produceconsume produceconsume 5
wproduce rconsumew r0 produce =... bw:=e... consume =... x:=b r... control = produce. w := w+1. consume. r := r+1. control w rproduceconsumeww := w+1rr := r+1 P W P W P W P W P W C R C R C R C R C produceconsumeconsumeconsume produceproducew=rpc n control = produce. w := mod (w+1) n. consume. r := mod (r+1) n. control consumeproducew=rproduce consumen, w=r ----------------------------------------------------------------------------------------------------------------------------------------------------------- 8.1.1 169 L sort = λn i, j: 0,..n i j L i L j sort n Ln (L' L) sort' (#L) t' t + (#L) 2 L swapi j = Li : = Lj Lj : = Li sort 0 sort 0 sort' (#L) sort 0 sort' (#L) for n:= 0;..#L do sort n sort' (n+1) sort n sort' (n+1) L 0 L 1 L 2 L 3 L 4 0 1 2 3 4 5 sort n sort' (n+1) if n = 0 then ok 6
else if L (n 1) L n then ok else (swap (n 1) n. sort(n 1) sort' n) sort n sort' (n+1) n, sort(n 1) sort' nn 1nfor- 1 C nl (n 1) L ns nswap (n 1) n#l=5 C1 S1 C2 S2 C1 S1 C3 S3 C2 S2 C1 S1 C4 S4 C3 S3 C2 S2 C1 S1 ij1s is js ic i C ic j C1 S1 C1 S1 C1 S1 C1 S1 C2 S2 C2 S2 C2 S2 C3 S3 C3 S3 C4 S4 -------------------------------------------------------------------------------------------------------------------------------------------------------- 8.1.2 384 (deadlock) 04 i 7
i i + 15 life = ( P0! P1! P2! P3! P4). life Pi = up i. up(i+1). eat i. down i. down(i+1) up i = chopstick i:= T down i = chopstick i:=! eat i =. chopstick i..chopstick(i+1).. life Pi Pi i Pi eat i chopstickeat i T i! j i! j i! j i! j i! j " i + 1! j i! j " i! i + 1 i! j " i + 1! j i! j " i! j + 1 i! j " i + 1! j " i! j + 1 life = P0 P1 P2 P3 P4 Pi = up i up(i+1). eat i. ( down i down(i+1)). Pi P0 P1 chopstick 1 ----------------------------------------------------------------------------------------------------------------------------------------------- 8
-------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------- 9