Download presentation
Presentation is loading. Please wait.
Published byHerbert Sherriff Modified over 9 years ago
1
ALICE AND BOB DISCOVER THE PETERSON'S ALGORITHM COSC 4330/6310 Summer 2013
2
The problem Alice and Bob share a critical section (CS) They want to ensure mutual exclusion They start by using the Reserve first and check later algorithm
3
How they implement it When one of them wants to enter the CS section, –It changes his/her status to "wants to enter the CS" –It repeatedly checks the status of his/her partner until this status is "is not interested" When one of them leaves the critical section, –It changes his/her status to "wants to enter the CS"
4
Stating point Alice is not interestedBob is not interested The critical section
5
Alice arrives Alice wants to use CSBob is not interested Alice is inside the CS She indicates her intention and enters the CS
6
Bob arrives Alice wants to use CSBob wants to use CS Alice is inside the CS Bob waits He indicates his intention but must wait
7
Alice leaves Alice is not interestedBob wants to use CS Bob is inside the CS Bob can now enter the CS
8
Alice and Bob arrive in lockstep Alice wants to use CSBob wants to use CS Deadlock Alice and Bob block each other
9
The tiebreaking rule When both Alice and Bob both want to enter the critical section, the last one to arrive (there is always one!) will wait –Works when one is already inside the critical section and the other arrive –Works when both arrive in lockstep
10
How they implement it (I) When one of them wants to enter the CS section, –He/she writes in a shared variable that he/she is the last one to request entry –He/she changes his/her status to "wants to enter the CS" –If he/she was the last one to request entry He/she repeatedly checks the status of his/her partner until this status is " is not interested "
11
How they implement it (II) When one of them leaves the critical section, –It changes his/her status to "is not interested"
12
Stating point Alice is not interestedBob does not The critical section Who arrived last?
13
Alice arrives Alice wants to use CSBob does not Alice is inside the CS Alice arrived last
14
Bob arrives Alice wants to use CSBob wants to use CS Alice is inside the CS Bob waits Bob arrived last
15
Alice leaves Alice is not interestedBob wants to use CS Bob is inside the CS Bob arrived last
16
Alice and Bob arrive in lockstep Alice wants to use CSBob wants to use CS Bob is inside the CS Alice arrived last Alice waits
17
How we implement it (I) Two shared variables –mustwait contains the process ID of the process that arrived last –reserved[2] an array such that reserved[i] == 1 if process i wants to enter the critical section reserved[i] == 0 otherwise
18
How we implement it (II) The entry rule is other = 1 - pid ; mustwait = pid;//last arrived while ((reserved[other] == 1) && (must wait == pid)) ; Busy wait
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.