Front | Back |
What is the problem of concurrency?
|
Sharing resources - some resources can only be safely used by one thread at a time.
|
Race Condition
|
Any situation where the order of execution of threads can cause different results. Programmers have no control.
|
How many threads do we want to be active in a critical section?
|
Only one.
|
Mutual Exclusion
|
Ensuring only one thread is active in a critical section.
|
Two causes of starvation due to mutual exclusion
|
|
Spin-Lock // Busy Wait
|
Waste of time - no work is actually being executed but the processor is being used and the process's time slice is being used up.
|
What are the three problems with this attempt at locking? |
|
Peterson's Solution to attempt 1
|
|
Problem with Peterson's Solution
|
Aside from all of the restrictions and that it only works with two threads, there is still a busy wait.
|
Bakery Algorithm - solves general case for more than two threads
|
Each thread is given a number indicating when it requests the lock i.e. scheduling number. These are not unique because they can be accessed concurrently, so we append the pid to it to make it unique. This number orders the access for the resource.
|
Interrupt Priority Level - way to solve Peterson's solution problem with gap between checking locked value and setting locked value
|
|
3 Disadvantages of Interrupt Priority Level
|
|
Test and Set - solution using hardware
|
|
Fairness of Spin Locks without Priorities
|
|
Fairness of Spin Locks with Priorities
|
|