1 / 9

CIS 720

CIS 720. Passing the Baton Technique. Cigarette Smokers Problem. Three smoker processes, one agent Each smoker needs 3 ingredients: tobacco, paper, match 1st smoker has tobacco, 2 nd smoker has paper 3 rd smoker has match

job
Download Presentation

CIS 720

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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

More Related