Mod 2: Critical Section / Mutual Exclusion Flashcards
What are some mechanisms to control access to shared resources?
(1) Locks
(2) Mutexes
(3) Semaphores
(4) Monitors
(5) Condition variables
What are some patterns for coordinating accesses to shared resources?
(1) Write-Reader
(2) Producer-Consumer (bounded buffer)
What is mutual exclusion?
Allowing only one thread to be in its critical section at a certain time, it means “not simultaneous”
How is mutual exclusion usually programmed?
By using locks
What is “condition synchronization”?
Signaling a condition (via shared variable) to allow threads waiting for an event signaled from another thread
What causes busy wait?
When something is waiting for a condition to come through and repeatedly test a variable until it comes true
When is synchronization needed?
Whenever a shared resource (a variable) is to be accessed by multiple threads
What is “critical sections/regions”?
Code blocks that may get incorrect results if executed simultaneously, these often access shared variables and must be protected
i.e statement that must not be executed by more than one thread at the time or part of code manipulating shared modifiable resources
What is mutual exclusion?
Mechanism that allows only one thread to enter the CS (critical section) at a time
What should we do to avoid race condition?
(1) Determine which part of the code is critical
(2) Ensure mutual exclusion
What is four requirements for CS solution?
(1) ME
(2) Progress (no deadlock or starvation)
(3) Fairness (no starvation)
(4) No assumption on performance
What does the requirement “progress” mean in CS context?
When no thread is in a CS, any thread requesting to enter must be allowed to do so without delay
What does “Fairness” mean in CS context?
That any thread waiting to access CS will at some point do that
What does “no assumption on performance” mean in CS context?
Overhead of entering and exiting should be small
What does “bounded wait” mean?
That there’s an uppe bound to the number of times a thread is allowed to enter its CS while other threads are waiting