r
play

r r tr - PowerPoint PPT Presentation

r r tr r r sr t ts void put(x) Val


  1. ❇♦✉♥❞❡❞ ❇✉✛❡r ❙❤❛♥❦❛r ❙❡♣t❡♠❜❡r ✶✽✱ ✷✵✶✹

  2. ❖✈❡r✈✐❡✇ ❇♦✉♥❞❡❞✲❜✉✛❡r s❡r✈✐❝❡ ✐♥♣✉t ❢✉♥❝t✐♦♥s✿ void put(x) ✱ Val get() ✱ void end() ♥♦ ♦✉t♣✉t ❢✉♥❝t✐♦♥s ■♠♣❧❡♠❡♥t❛t✐♦♥s ✉s✐♥❣ st❛♥❞❛r❞ s②♥❝❤r♦♥✐③❛t✐♦♥ ❝♦♥str✉❝ts ❧♦❝❦s✱ ❝♦♥❞✐t✐♦♥ ✈❛r✐❛❜❧❡s s❡♠❛♣❤♦r❡s ■♠♣❧❡♠❡♥t❛t✐♦♥s ✉s✐♥❣ ❛✇❛✐t s②♥❝❤r♦♥✐③❛t✐♦♥ ❝♦♥str✉❝ts ♠♦r❡ ♣♦✇❡r❢✉❧✱ ❝♦♥✈❡♥✐❡♥t ♠❡❝❤❛♥✐❝❛❧ tr❛♥s❢♦r♠❛t✐♦♥ t♦ st❛♥❞❛r❞ s②♥❝❤ ❝♦♥str✉❝ts ❘❡❞✉❝❡ ❜❧♦❝❦✐♥❣ ✭✐♥❝r❡❛s❡ ♣❛r❛❧❧❡❧✐s♠✮ ✐♥ ✐♠♣❧❡♠❡♥t❛t✐♦♥s ❈❛♥❝❡❧❧✐♥❣ ❜❧♦❝❦❡❞ ❝❛❧❧s t♦ r❡♠♦t❡ s②st❡♠s ❛❧❧♦✇s ❛ ❝❛❧❧❡r ♥♦ ❧♦♥❣❡r ✐♥t❡r❡st❡❞ ✐♥ ❝❛❧❧ t♦ r❡tr✐❡✈❡ ✐ts❡❧❢

  3. ❖✉t❧✐♥❡ s❡r✈✐❝❡ ❇♦✉♥❞❡❞✲❇✉✛❡r ❙❡r✈✐❝❡ ❇♦✉♥❞❡❞✲❇✉✛❡r ❙❡r✈✐❝❡ ■♥✈❡rs❡ ❆✇❛✐ts ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ❆✇❛✐ts ▲♦❝❦s ❛♥❞ ❈♦♥❞✐t✐♦♥ ❱❛r✐❛❜❧❡s ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ▲♦❝❦s ❛♥❞ ❈♦♥❞✐t✐♦♥ ❱❛r✐❛❜❧❡s ❙❡♠❛♣❤♦r❡s ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ❙❡♠❛♣❤♦r❡s ✴✴ ❙❊❊ ❚❊❳❚ ■♥❝r❡❛s✐♥❣ P❛r❛❧❧❡❧✐s♠ ❈❛♥❝❡❧✐♥❣ ❇❧♦❝❦❡❞ ❈❛❧❧s ✴✴ ❙❊❊ ❚❊❳❚

  4. ❇♦✉♥❞❡❞✲❇✉✛❡r ❙❡r✈✐❝❡ ✕ ✶ s❡r✈✐❝❡ ❋✐❢♦ ❜♦✉♥❞❡❞ ❜✉✛❡r ♦❢ s✐③❡ N ✐♥♣✉t ❢✉♥❝t✐♦♥s✿ put(x) ✱ get() ✱ end() ♥♦ ♦✉t♣✉t ❢✉♥❝t✐♦♥s ▼❛✐♥ buff ✿ s❡q✉❡♥❝❡ ♦❢ ✐t❡♠s ✐♥ ❜✉✛❡r ending ✿ tr✉❡ ✐✛ end() ❤❛s ❜❡❡♥ ❝❛❧❧❡❞ putBusy ✿ tr✉❡ ✐✛ put ❝❛❧❧ ♦♥❣♦✐♥❣ getBusy ✿ tr✉❡ ✐✛ get ❝❛❧❧ ♦♥❣♦✐♥❣ void mysid.put(x) ✐❝ ④♥♦t ❡♥❞✐♥❣ ❛♥❞ ♥♦ ♦♥❣♦✐♥❣ put ❝❛❧❧⑥ ♦❝ ④ buff ❤❛s s♣❛❝❡⑥ ❛♣♣❡♥❞ x t♦ buff ❀ r❡t✉r♥

  5. ❇♦✉♥❞❡❞✲❇✉✛❡r ❙❡r✈✐❝❡ ✕ ✷ s❡r✈✐❝❡ Val mysid.get() ✐❝ ④♥♦t ❡♥❞✐♥❣ ❛♥❞ ♥♦ ♦♥❣♦✐♥❣ get ❝❛❧❧⑥ ♦✉t♣✉t rval ♦❝ ④ buff ❤❛s ✐t❡♠✱ rval ✐s buff.head ⑥ ❜❡❤❡❛❞ buff ❀ r❡t✉r♥ rval void mysid.end() ✐❝ ④♥♦t ❡♥❞✐♥❣⑥ s❡t ❡♥❞✐♥❣ ♦❝ ④tr✉❡⑥ r❡t✉r♥ Pr♦❣r❡ss ❛ss✉♠♣t✐♦♥ put ❝❛❧❧ r❡t✉r♥s ✐❢ buff ❤❛s s♣❛❝❡ ✴✴ ✉s❡s putBusy get ❝❛❧❧ r❡t✉r♥s ✐❢ buff ❤❛s ✐t❡♠ ✴✴ ✉s❡s getBusy end ❝❛❧❧ r❡t✉r♥s ✴✴ ✉s❡s ✏t❤r❡❛❞ ✐♥ mysid.end ✑

  6. BoundedBuffer(int N) ✕ ✶ s❡r✈✐❝❡ // main input Val mysid.get() ic {N ≥ 1} ic {not ending and buff ← []; not getBusy} ending ← false; getBusy ← true; putBusy ← false; output(Val rval) getBusy ← false; oc {buff.size > 0 return mysid; and rval = buff[0]} buff.remove(); input void mysid.put(Val x) getBusy ← false; ic {not ending and return rval; not putBusy} putBusy ← true; input void mysid.end() oc {buff.size < N} ic {not ending} buff.append(x); ending ← true; putBusy ← false; oc {true} return; return;

  7. BoundedBuffer(int N) ✕ ✷ s❡r✈✐❝❡ atomicity assumption {input and output parts} progress assumption { // thread in put returns if buffer has space (putBusy and buff.size < N) ❧❡❛❞s✲t♦ not putBusy; // thread in get returns if buffer has an item (getBusy and buff.size > 0) ❧❡❛❞s✲t♦ not getBusy; // thread in end returns (thread u in mysid.end) ❧❡❛❞s✲t♦ (not u in mysid.end); } }

  8. ❖✉t❧✐♥❡ s❡r✈✐❝❡ ✐♥✈❡rs❡ ❇♦✉♥❞❡❞✲❇✉✛❡r ❙❡r✈✐❝❡ ❇♦✉♥❞❡❞✲❇✉✛❡r ❙❡r✈✐❝❡ ■♥✈❡rs❡ ❆✇❛✐ts ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ❆✇❛✐ts ▲♦❝❦s ❛♥❞ ❈♦♥❞✐t✐♦♥ ❱❛r✐❛❜❧❡s ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ▲♦❝❦s ❛♥❞ ❈♦♥❞✐t✐♦♥ ❱❛r✐❛❜❧❡s ❙❡♠❛♣❤♦r❡s ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ❙❡♠❛♣❤♦r❡s ✴✴ ❙❊❊ ❚❊❳❚ ■♥❝r❡❛s✐♥❣ P❛r❛❧❧❡❧✐s♠ ❈❛♥❝❡❧✐♥❣ ❇❧♦❝❦❡❞ ❈❛❧❧s ✴✴ ❙❊❊ ❚❊❳❚

  9. ❙❡r✈✐❝❡ ■♥✈❡rs❡ ❖✈❡r✈✐❡✇ ✕ ✶ s❡r✈✐❝❡ ✐♥✈❡rs❡ BoundedBufferInverse(N, bb) ✴✴ bb ✿ s✐❞ ♦❢ ✐♠♣❧❡♠❡♥t❛t✐♦♥ ♠❛✐♥✿ buff ✱ ending ✱ putBusy ✱ getBusy ♦✉t♣✉t ❢✉♥❝t✐♦♥s✿ doPut(x) ✱ doGet() ✱ doEnd() doPut(x) ♦❝ ④♥♦t ❡♥❞✐♥❣ ❛♥❞ ♥♦ ♦♥❣♦✐♥❣ put ❝❛❧❧⑥ bb.put(x) ✐❝ ④ buff ❤❛s s♣❛❝❡⑥ ❛♣♣❡♥❞ x t♦ buff doGet() ♦❝ ④♥♦t ❡♥❞✐♥❣ ❛♥❞ ♥♦ ♦♥❣♦✐♥❣ get ❝❛❧❧⑥ rval ← bb.get() ✐❝ ④ buff ❤❛s ✐t❡♠✱ rval ✐s buff.head ⑥ ❜❡❤❡❛❞ buff

  10. ❙❡r✈✐❝❡ ■♥✈❡rs❡ ❖✈❡r✈✐❡✇ ✕ ✷ s❡r✈✐❝❡ ✐♥✈❡rs❡ doEnd() ♦❝ ④♥♦t ❡♥❞✐♥❣⑥ s❡t ❡♥❞✐♥❣❀ bb.end() ✐❝ ④tr✉❡⑥ r❡t✉r♥ ♣r♦❣r❡ss ❝♦♥❞✐t✐♦♥ put ❝❛❧❧ r❡t✉r♥s ✐❢ buff ❤❛s s♣❛❝❡ ✴✴ ✉s❡s putBusy get ❝❛❧❧ r❡t✉r♥s ✐❢ buff ❤❛s ✐t❡♠ ✴✴ ✉s❡s getBusy end ❝❛❧❧ r❡t✉r♥s ✴✴ ✉s❡s ✏t❤r❡❛❞ ✐♥ bb.end ✑

  11. BoundedBufferInverse(N, bb) s❡r✈✐❝❡ ✐♥✈❡rs❡ // main output doGet() { ic {N ≥ 1} oc {not ending and not getBusy} buff ← []; getBusy ← true; putBusy ← false; Val x ← bb.get(x); getBusy ← false; ic {buff.size > 0 and x = buff[0]} return mysid; buff.remove(); getBusy ← false; output doPut(Val x) { oc {not end- output doEnd() { ing and oc {not ending} not putBusy} ending ← true; putBusy ← true; lck.end(); bb.put(x); ic {true} ic {buff.size < N} buff.append(x); progress condition {... mysid bb...} putBusy ← false;

  12. ❖✉t❧✐♥❡ ❛✇❛✐t ❇♦✉♥❞❡❞✲❇✉✛❡r ❙❡r✈✐❝❡ ❇♦✉♥❞❡❞✲❇✉✛❡r ❙❡r✈✐❝❡ ■♥✈❡rs❡ ❆✇❛✐ts ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ❆✇❛✐ts ▲♦❝❦s ❛♥❞ ❈♦♥❞✐t✐♦♥ ❱❛r✐❛❜❧❡s ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ▲♦❝❦s ❛♥❞ ❈♦♥❞✐t✐♦♥ ❱❛r✐❛❜❧❡s ❙❡♠❛♣❤♦r❡s ❇♦✉♥❞❡❞✲❇✉✛❡r ■♠♣❧❡♠❡♥t❛t✐♦♥ ✉s✐♥❣ ❙❡♠❛♣❤♦r❡s ✴✴ ❙❊❊ ❚❊❳❚ ■♥❝r❡❛s✐♥❣ P❛r❛❧❧❡❧✐s♠ ❈❛♥❝❡❧✐♥❣ ❇❧♦❝❦❡❞ ❈❛❧❧s ✴✴ ❙❊❊ ❚❊❳❚

  13. ❆✇❛✐t ❝♦♥str✉❝t ❛✇❛✐t ❆✇❛✐t✿ ♣♦✇❡r❢✉❧ s②♥❝❤r♦♥✐③❛t✐♦♥ ❝♦♥str✉❝t ♥♦t ♣r♦✈✐❞❡❞ ❜② P▲s ❝♦♥✈❡♥✐❡♥t ❢♦r ✇r✐t✐♥❣ ♣r♦❣❛♠s ✐♠♣❧❡♠❡♥t❛❜❧❡ ❜② st❛♥❞❛r❞ s②♥❝❤r♦♥✐③❛t✐♦♥ ❝♦♥str✉❝ts await (B) S B ✐s ♣r❡❞✐❝❛t❡✱ S ✐s ♥♦♥✲❜❧♦❝❦✐♥❣ ❝♦❞❡ ❛t♦♠✐❝❛❧❧② ❡①❡❝✉t❡ S ♦♥❧② ✐❢ B ❤♦❧❞s✱ ♦t❤❡r✇✐s❡ ✇❛✐t ✇❡❛❦ ♦r str♦♥❣ ❢❛✐r♥❡ss await (B) S ✿ ♠♦r❡ ❣❡♥❡r❛❧ t❤❛♥ oc {B} S S ❝❛♥ ♠❛❦❡ ✭♥♦♥✲❜❧♦❝❦✐♥❣✮ ♦✉t♣✉t ❝❛❧❧s✱ ✉s❡ r❡t✉r♥ ✈❛❧✉❡s atomic S ✿ s❤♦rt ❢♦r await (true) S

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend