Mutual Exclusion andSynchronization
Wikipedia
We have features for every step of the way
Design, organize, and collaborate
Semaphore                                                        o                o                                    
Stylize, edit, and animate your media
Broadcast and compress for seamless delivery
semSignal semWait    semWait                                wait                                              
semaphore s=1;P0 ()               P1 (){                   {  semWait (s);        semWait (s);   <CS>                <CS> ...
•n   •    •    15
semaphore s=1;P0 ()                P1 (){                    {  semWaitB (s);        semWaitB (s);   <CS>                 ...
Producer and Consumer                            •                            •                        –                  ...
•    •––    •–    18
producer:                consumer:while (true)             while (true) {                        {/* produce item v   */  ...
n    delay            (n=1)            20
21
22
nwait           23
y                    x                                        •                                                           ...
S                                    a              P3 P2 P1             •S                                             se...
P1    P2    P3     P2     P1     P3     P2    P2    P3      P1    W(a) W(a)   S(a)   W(a)   S(a)   S(a)   W(a) W(a)   S(a)...
27
28
n   n       •        n            •            •            •        –            29
•30
31
Monitor              •              •              •          –          –          –              •              32
33
cwait(c)    •              c                  csignal (c)   •         cwaitwait/signal                     •              ...
35
•••36
•37
mayconsume    •                capacity                           •             mayproducemayproduce                 •    ...
Mutual exclusion and synchronization
Mutual exclusion and synchronization
Mutual exclusion and synchronization
Mutual exclusion and synchronization
Mutual exclusion and synchronization
Upcoming SlideShare
Loading in...5
×

Mutual exclusion and synchronization

2,635

Published on

Operating Systems - William Stallings
Persian
Chapter5-2 semaphore Function
Mutual exclusion and synchronization

mahmood alemi
Ahmad niroomand

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,635
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Ahmadniroomand
  • Mutual exclusion and synchronization

    1. 1. Mutual Exclusion andSynchronization
    2. 2. Wikipedia
    3. 3. We have features for every step of the way
    4. 4. Design, organize, and collaborate
    5. 5. Semaphore   o o   
    6. 6. Stylize, edit, and animate your media
    7. 7. Broadcast and compress for seamless delivery
    8. 8. semSignal semWait semWait  wait  
    9. 9. semaphore s=1;P0 () P1 (){ { semWait (s); semWait (s); <CS> <CS> semSignal (s); semSignal (s);} }
    10. 10. •n • • 15
    11. 11. semaphore s=1;P0 () P1 (){ { semWaitB (s); semWaitB (s); <CS> <CS> semSignalB (s); semSignalB (s);} } 16
    12. 12. Producer and Consumer • • – • – 17
    13. 13. • •–– •– 18
    14. 14. producer: consumer:while (true) while (true) { {/* produce item v */ while (in <= out) b[in] = v; /* do nothing */; in++} w = b[out]; out = (out + 1); /* consume item w */ } 19
    15. 15. n delay (n=1) 20
    16. 16. 21
    17. 17. 22
    18. 18. nwait 23
    19. 19. y x • z x Processes z yW(z) z n>=0 y x W(y) z n>=0 y n>=1 x W(x) z y x z n>=0 y x <CS> S(x) (n>=0) z z • S(y) y zS(z) x y y.. x 24
    20. 20. S a P3 P2 P1 •S semWait W semSignal P1 P2 P3 P2 P1 P3 P2 P2 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. 21. P1 P2 P3 P2 P1 P3 P2 P2 P3 P1 W(a) W(a) S(a) W(a) S(a) S(a) W(a) W(a) S(a) W(a)a 0 -1 0 -1 0 1 0 -1 0 -1 P2 P2 P2 P1 26
    22. 22. 27
    23. 23. 28
    24. 24. n n • n • • • – 29
    25. 25. •30
    26. 26. 31
    27. 27. Monitor • • • – – – • 32
    28. 28. 33
    29. 29. cwait(c) • c csignal (c) • cwaitwait/signal • 34
    30. 30. 35
    31. 31. •••36
    32. 32. •37
    33. 33. mayconsume • capacity • mayproducemayproduce • 38
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×