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

CIS 720

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

CIS 720

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

  1. CIS 720 Passing the Baton Technique

  2. Cigarette Smokers Problem • Three smoker processes, one agent • Each smoker needs 3 ingredients: tobacco, paper, match • 1st smoker has tobacco, • 2nd smoker has paper • 3rd smoker has match • Agent randomly puts two ingredients on the table and the smoker that does not have these two ingredients picks them up and smokes. Agents waits until the smoker has finished smoking.

  3. Solution using semaphores • Smoker1: do true  P(paper); P(match); smoke; V(done) od • Smoker2: • do true  P(paper); P(tobacco); smoke; V(done) od • Smoker3: • do true  P(match); P(tobacco); smoke; V(done) od • Agent: • do true  if true  V(paper); V(tobacco); • [] true  V(paper); V(match); • [] true  V(match); V(tobacco); • fi; • P(done) • od

  4. inm = number of matches deposited • outm = number of matches consumed • int = number of tobacco deposited • outt = number of tobacco consumed • inp = number of paper deposited • outp = number of paper consumed

  5. Solution using semaphores • Smoker1: do true  < outp = outp + 1; outm = outm + 1 > smoke done = true od • Agent: do true  < await (done)  if true  inp = inp + 1; inm = inm + 1 [] true  inp = inp + 1; int = int + 1 [] true  int = int + 1; inm = inm + 1 fi >

  6. Solution using semaphores • Smoker1: do true  < await (inp > outp /\ inm > outm)  outp = outp + 1; outm = outm + 1 > smoke <done = true> od • Agent: do true  < await( done)  done = false; if true  inp = inp + 1; inm = inm + 1 [] true  inp = inp + 1; int= int+ 1 [] true  int= int+ 1; inm = inm + 1 fi >

  7. Solution using semaphores • Smoker1: do true  P(e); if (inp == outp \/ inm == outm)  d1++; V(e); P(s1) fi outp = outp + 1; outm = outm + 1; SIGNAL smoke P(e); done = true; SIGNAL od

  8. Solution using semaphores • Agent: do true  P(e); if !done  da++; V(e); P(d) fi; done = false; if true  inp = inp + 1; inm = inm + 1 [] true  inp = inp + 1; inm = inm + 1 [] true  inp = inp + 1; inm = inm + 1 fi od

  9. SIGNAL: If (inp > outp /\ inm > outm /\ d1 > 0  d1--; V(s1) [] (inp > outp /\ int > outt /\ d2 > 0  d2--; V(s2) [] (inm > outm /\ int > outt /\ d3 > 0  d3--; V(s3) [] (done /\ da > 0  da--; V(d) [] else  V(e) fi