Front | Back |
What is IPC and why is it needed?
|
Interprocess Communication is needed when1. Two or more processes want to share/exchange data2. To prevent processes that enter a critical region from interfering with one another3. To ensure process dependencies are correctly sequenced (read then write)
|
What is the bounded buffer problem?
|
*Two processes share a common fixed length buffer* Producer deposits, Consumer consumesProblem: Producer attempts to deposit but buffer is full / Consumer attempts to withdrawal but buffer is empty
|
What is the solution to the bounded buffer problem?
|
Producer sleeps until awakened by consumer when buffer is NOT full / Consumer sleeps until awakened by Producer when buffer is NOT empty
|
What are race conditions?
|
When two processes attempt to read and/or write shared data and the final result depends on the order in which they are run
|
Solution to race conditions
|
Critical Regions to provide Mutual Exclusion
|
Critical Region
|
Part of the program where shared data is accessed
|
What are the four conditions critical regions to provide mutual exclusion must meet?
|
1. No two processes simultaneously inside CR2. No assumptions may be made about the speed or number of CPUs3. No process running outside its CR may block another process4. No process should have to wait forever to enter its critical region
|
Busy waiting Strict Alternation
|
Goal: Use a shared variable to keep track of whose turn it is to enter the critical region-Violates condition 3: Process can forced to wait for a process in a non-critical region->Taking turns is not a good solution when onr process is slower than the other
|
Busy waiting
|
Continuously testing a variable until some value appears (wastes CPU time)
|
Spin lock
|
Waiting process spins in a tight loop reading a variable waiting to see if it can proceed
|
Busy Wait: Working Solution(Peterson's Algorithm)
|
Goal: Use lock/warning variables to remove strict alternationELABORATION:*before entering critical region, each process calls enter_region and waits until it is safe to enter*while inside set flag interested to trueIf another process is not enterested enter_region returns immediately* If not process hangs until interested flag goes false*flag is set to false when a process EXITS the critical region
|
Mutual Exclusion Types & disadvantages
|
1. Busy wait w/ Strict Alternation2. Busy wait w/ flags3. Bakery Algorithm (busy wait for multiple processes)*ALL are adequate but waste CPU resources (loops)SOLUTION: use hardware
|
Hardware Solutions for IPC
|
1. Test & Set - test and set a variable in one instruction2. Atomic swap - switch register & memory in one instruction3. Turn off interrupts - processes won't be switched out unless it asks to be suspended
|
Mutual Exclusion using Hardware
|
Two types: Test & set and Swap*single shared variable lock+ uses busy wait, but simpler+ works for any number of processes-non concurrent code can lead to unbounded waiting-priority inversion
|
Priority inversion
|
Higher priority process waits for lower priority process
|