CIS 720 Lecture 4
i := 1 max := A[1] do i < n i = i + 1 if (max < A[i]) max = A[i] od
Concurrency rule for all i, { Pi } Si { Qi } { P1 /\ …. /\ Pn } co S1 // …. // Sn { Q1 /\ …. /\ Qn}
x = 0; y = 1; x = 0; co co x = 1 x = x + 1 // // y = y + 1 x = x + 2 oc oc
Interference freedom Let a be a statement and C be an assertion. NI(a, C) iff { pre(a) /\ C } a { C } Execution of a does not invalidates (or interferes) with C.
{ Pi } Si { Qi }, for all I, are interference free if for all assertions C in proof outline of Si, for all actions a in Sj, i != j NI(a, C) holds
Concurrency rule { Pi } Si { Qi } are interference free { P1 /\ …. /\ Pn } co S1 // …. // Sn { Q1 /\ …. /\ Qn}
x= 0; co x = x + 1 // x = x + 2 od
Bank transactions co // Transfer(x,y,am): Auditor: ac[x] = ac[x] – am; total = 0; i = 0; ac[y] = ac[y] + am do i < n total = total + ac[i] i = i + 1 od oc
Bank transactions co // Transfer(x,y,am): Auditor: if < !auditon ac[x] = ac[x] – am; auditon = 1; total = 0; i = 0; ac[y] = ac[y] + am > [] do i < n <auditon && ( (x < i && y < i) ||(x > I && y > i)) total = total + ac[i] ac[x] = ac[x] – am; ac[y] = ac[y] + am> i = i + 1 fi od auditon = 0 oc
Techniques to avoid interference Disjoint variables If the write set of each process is disjoint from the read and write set of other processes, then the proof outlines will be interference free.
Avoiding interference Weakened assertions x= 0; co x = x + 1 // x = x + 2 od
Avoiding interference Global Invariants: Assume that every assertion in the proof outline of Pi is of the form I /\ L, where L refers to local variables of Pi or to variables that only Pi writes. - Then the proof outlines will be interference free.
Concurrency rule for all i, { I} Si { I } { I } co S1 // …. // Sn { I}
Avoiding interference Synchronization