Mutual exclusion and synchronization

38
ل و ب ا ق ت م صار ح ن ا ي ن ما ز م ه ل ص ف5 ) دوم ت م س ق( Mutual Exclusion and Synchronization

description

Operating Systems - William Stallings Persian Chapter5-2 semaphore FunctionMutual exclusion and synchronizationmahmood alemiAhmad niroomand

Transcript of Mutual exclusion and synchronization

  • 1. Mutual Exclusion andSynchronization

2. Wikipedia 3. We have features for every step of the way 4. Design, organize, and collaborate 5. Semaphoreoo 6. Stylize, edit, and animate your media 7. Broadcast and compress for seamless delivery 8. semSignal semWaitsemWaitwait 9. semaphore s=1;P0 () P1 (){ {semWait (s);semWait (s); semSignal (s);semSignal (s);} } 10. n 15 11. semaphore s=1;P0 ()P1 (){{semWaitB (s);semWaitB (s); semSignalB (s);semSignalB (s);}}16 12. Producer and Consumer17 13. 18 14. producer:consumer:while (true) while (true) {{/* produce item v */while (in =0 yx W(y) zn>=0 y n>=1 xW(x) zyx z n>=0 yx S(x) (n>=0) zz S(y)yzS(z)xyy..x24 20. SaP3 P2 P1 S semWait W semSignalP1 P2 P3 P2 P1 P3 P2P2 P3 P1W(a) W(a) S(a) W(a) S(a) S(a)W(a) W(a) S(a) W(a) P3 P2 P1 P2 P3 P1 P1 P3 P2 25 21. P1P2P3 P2 P1 P3 P2P2P3P1W(a) W(a) S(a) W(a) S(a) S(a) W(a) W(a) S(a) W(a)a0-1 0-1 010-1 0-1P2 P2 P2P1 26 22. 27 23. 28 24. n n n29 25. 30 26. 31 27. Monitor32 28. 33 29. cwait(c)ccsignal (c) cwaitwait/signal 34 30. 35 31. 36 32. 37 33. mayconsumecapacity mayproducemayproduce 38