5.3.2 Two Uses of Semaphores(3/18 ·2. Synchronization Enforcing some order between threads Semaphore usually has an initial value of o semaphore wait_left=0; semaphore wait_ right =0; Left_ Paw(t Right Paw( i slide_ left( P(wait_left) W(wait_left); slide_lefto; P(wait_ right); slide- right( slide- right(; W(wait_ right);
5.3.2 Two Uses of Semaphores(3/18) • 2. Synchronization • Enforcing some order between threads • Semaphore usually has an initial value of 0 * semaphore wait_left = 0; semaphore wait_right = 0; Left_Paw() { Right_Paw() { slide_left(); P(wait_left); V(wait_left); slide_left(); P(wait_right); slide_right(); slide_right(); V(wait_right); } }
5.3.2 Two Uses of Semaphores(4/18 ·2. Synchronization Enforcing some order between threads Semaphore usually has an initial value of o semaphore wait left = 0; wait left =0 semaphore wait right =0; wait_right =0 Left_ Paw(t Right Paw( i slide_ left( P(wait_left) W(wait_left); slide_lefto P(wait_ right); slide- right( slide- right(; W(wait_ right); 必
5.3.2 Two Uses of Semaphores(4/18) • 2. Synchronization • Enforcing some order between threads • Semaphore usually has an initial value of 0 18 semaphore wait_left = 0; semaphore wait_right = 0; Left_Paw() { Right_Paw() { slide_left(); P(wait_left); V(wait_left); slide_left(); P(wait_right); slide_right(); slide_right(); V(wait_right); } } wait_left = 0 wait_right = 0
5.3.2 Two Uses of Semaphores(5/18 ·2. Synchronization Enforcing some order between threads Semaphore usually has an initial value of o semaphore wait_left =0; wait left =0 semaphore wait_ right =0; wait_right =0 Left PawoI Right Pawo( slide_ left( P(wait_left) W(wait_left); slide_lefto; P(wait_ right); slide- right( slide- right(; W(wait_ right); 必
5.3.2 Two Uses of Semaphores(5/18) • 2. Synchronization • Enforcing some order between threads • Semaphore usually has an initial value of 0 * semaphore wait_left = 0; semaphore wait_right = 0; Left_Paw() { Right_Paw() { slide_left(); P(wait_left); V(wait_left); slide_left(); P(wait_right); slide_right(); slide_right(); V(wait_right); } } wait_left = 0 wait_right = 0
5.3.2 Two Uses of Semaphores(6/18 ·2. Synchronization Enforcing some order between threads Semaphore usually has an initial value of o semaphore wait_left =0; wait left =0 semaphore wait_ right =0; wait_right =0 Left PawoI Right Paw( i slide_ left( P(wait left) W(wait_left); slide_lefto; P(wait_ right); slide- right( slide- right(; v(wait_right); ait
5.3.2 Two Uses of Semaphores(6/18) • 2. Synchronization • Enforcing some order between threads • Semaphore usually has an initial value of 0 * semaphore wait_left = 0; semaphore wait_right = 0; Left_Paw() { Right_Paw() { slide_left(); P(wait_left); V(wait_left); slide_left(); P(wait_right); slide_right(); slide_right(); V(wait_right); } } wait wait_left = 0 wait_right = 0
5.3.2 Two Uses of Semaphores(7/18 ·2. Synchronization Enforcing some order between threads Semaphore usually has an initial value of o semaphore wait_left=0; wait left =0 semaphore wait_ right =0; wait_right =0 Left_ Paw(t Right Paw( i slide lefto P(wait left) W(wait_left); slide_lefto; P(wait_ right); slide- right( slide- right(; W(wait_ right);
5.3.2 Two Uses of Semaphores(7/18) • 2. Synchronization • Enforcing some order between threads • Semaphore usually has an initial value of 0 * semaphore wait_left = 0; semaphore wait_right = 0; Left_Paw() { Right_Paw() { slide_left(); P(wait_left); V(wait_left); slide_left(); P(wait_right); slide_right(); slide_right(); V(wait_right); } } wait_left = 0 wait_right = 0