Download
cis 720 n.
Skip this Video
Loading SlideShow in 5 Seconds..
CIS 720 PowerPoint Presentation

CIS 720

134 Vues Download Presentation
Télécharger la présentation

CIS 720

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. CIS 720 Invariant Based Methodology

  2. Producer/consumer problem co Producer: Consumer: do true  do true  produce pdata buf = pdata cdata = buf; consume cdata od od oc

  3. Producer/consumer problem in1 = out1 = in2 = out2 = 0; co Producer: Consumer: do true  {in1=out1}do true  {in2=out2} produce pdata in1 = in1 + 1 in2 = in2 + 1 buf = pdata{in1 = out1+1}cdata = buf{in2 = out2+1} out1 = out1 + 1 out2 = out2 + 1 {in1=out1} consume cdata{in2 = out2} od od oc Invariant:

  4. Producer/consumer problem co Producer: Consumer: do true  do true  produce pdata <await(in1 <=out2)  in1 = in1 + 1> <await(in2 < out1) in2 = in2 + 1> buf = pdatacdata = buf <out1 = out1 + 1> <out2 = out2 + 1> consume cdata od od oc Invariant: (in1 <= out2 + 1) /\ (in2 <= out1)

  5. Producer/consumer problem co Producer: Consumer: do true  do true  produce pdata <await(empty > 0)  empty= empty -1><await(full > 0)  full = full -1 > buf = pdata cdata = buf <full = full + 1><empty = empty + 1> consume cdata od od oc Invariant: (in1 <= out2 + 1) /\ (in2 <= out1) empty = out2 + 1 in1 full = out1 – in2

  6. Producer/consumer problem co Producer: Consumer: do true  do true  produce pdata P(empty) P(full) buf = pdata cdata = buf V(full) V(empty) consume cdata od od oc Invariant: (in1 <= out2 + 1) /\ (in2 <= out1) empty = out2 + 1 in1 full = out1 – in2

  7. Producer/consumer problem in1 = out1 = in2 = out2 = 0; co Producer: Consumer1: Consumer2: do true  do true  do true  produce pdata in1 = in1 + 1 in2 = in2 + 1 in3 = in3 + 1 buf = pdata cdata = buf cdata = buf out1 = out1 + 1 out2 = out2 + 1 out3 = out3 + 1 consume cdata consume cdata od od od oc Invariant:

  8. Readers/writers problem • A reader and a writer cannot read and write respectively at the same time. • Two writers cannot write at the same time.

  9. Readers/writers problem co Reader[i]: Writer[j]: do true  do true  P(rw) P(rw) read write V(rw) V(rw) od od oc

  10. Readers/writers problem co Reader[i]: Writer: do true  do true  nr = nr + 1 P(rw) if nr == 1  P(rw) fi write read nr = nr - 1 if (nr =0) V(rw) fi V(rw) od od oc

  11. Readers/writers problem co Reader[i]: Writer: do true  do true  nr=nr+1 nw = nw + 1 read write nr = nr - 1 nw = nw - 1 od od oc

  12. Readers/writers problem co Reader[i]: Writer: do true  do true  nr=nr+1 nw = nw + 1 read write nr = nr - 1 nw = nw - 1 od od oc BAD = (nr > 0 /\ nw > 0 ) \/ nw > 1 Invariant: not (BAD) (nr = 0 \/ nw = 0) /\ nw <= 1

  13. Readers/writers problem co Reader[i]: Writer: do true  do true  inr = inr + 1 inw = inw + 1 read write outr = outr + 1 outw = outw + 1 od od oc

  14. Readers/writers problem co Reader[i]: Writer: do true  do true  inr = inr + 1 inw = inw + 1 read write outr = outr + 1 outw = outw + 1 od od oc BAD = Invariant:

  15. Technique of Passing the baton • Solution may contain statements • F1 : <S> • F2 : < await (Bj)  Sj > • Introduce the following semaphores • e : for controlling access to evaluate the conditions • bj : for each guard Bj

  16. Introduce a new counter dj for each guard Bj • Replace as follows: • F1: P(e) Sj SIGNAL

  17. Readers/writers problem co Reader[i]: Writer: do true  do true  <await(nw = 0)  nr=nr+1> <await(nw=0 /\ nr = 0)  nw = nw + 1> read write <nr = nr – 1><nw = nw – 1> od od oc

  18. Readers/writers problem co Reader[i]: do true  <await(nw = 0)  nr=nr+1> read <nr = nr – 1> od oc

  19. Readers/writers problem co Writer: do true  <await(nw=0 /\ nr = 0)  nw = nw + 1> write <nw = nw – 1> od oc

  20. SIGNAL if (nw = 0 and dr > 0)  dr = dr – 1; V(r) elseif (nw = 0 and nr = 0 and dw > 0)  dw = dw – 1; V(w) else V(e)

  21. co Reader[i]: Writer: do true  do true  P(e) P(e) if (nw > 0) dr++; V(e); P(r) fi if (nw=0 /\ nr = 0)  dw++; V(e); P(w) finr++; nw++; SIGNAL SIGNAL read write P(e) P(e) nr--; nw-- SIGNAL SIGNAL od od oc • SIGNAL • if (nw = 0 and dr > 0)  dr = dr – 1; V(r) • elseif • (nw = 0 and nr = 0 and dw > 0)  dw = dw – 1; V(w) • else V(e)

  22. Weak Reader preference • If a reader A is reading and a reader B and a writer C is waiting then B is given preference.

  23. Strong Reader preference • If a reader B and a writer C is waiting then B is given preference.

  24. Strong Writer preference • If a reader B and a writer C is waiting then C is given preference. • SIGNAL: If nw = 0 /\ dr > 0 /\ dw = 0  dr = dr – 1; V(r) [] nr = 0 /\ nw = 0 /\ dw > 0  dw = dw – 1; V(w); [] else -> V(e) fi