ch.7 Mutual Exclusion Flashcards
what are the 3 mutual exclusion solutions?
strict alternation, Dekkers Algorithm, the bakery algorithm
what four things must be ensured for Mutual Exclusion?
- only one thread in CS
- any number of threads
- threads outside of CS cannot block another thread
- no thread can wait forever
what is the strict Alternation algorithm
uses a shared variable to determine who goes first
ex: int next = 0 blocks and int = 1 continues
which mutual exclusion properties does the strict algorithm work for?
only one thread in CS and can be extended to more than one thread
which mutual exclusion property does the strict algorithm not work for?
a thread can be blocked outside of the critical section
a thread can wait forever
What is Dekkers Algorithm?
unselfish algorithm -> each thread waits until the thread has completed their process (achieves all four mutual exclusion properties but it has issues)
what are some issues with Dekkers Algorithm?
- inefficient while loops (uses a lot of resources)
- potential to deadlock if both are waiting for the other to take their turn
- live lock can occur if each thread keep yielding to the other thread
- hard to scale
what is the bakery Algorithm?
an analogy : a bakery’s ticket counter
a. thread “enters” the “bakery”
b. thread “gets” the next ticket
c. thread waits for its turn
provides mutual exclusion
what is the best property of the bakery algorithm?
the algorithm does not depend on the output of a thread
ex: if there are concurrent read and write operations the algorithm does not depend upon a correct read, the read can return any arbitrary value!