Please enable JavaScript.
Coggle requires JavaScript to display documents.
Lecture 8: Mutex exclusion Async Completion (Fix (Atomic CPU…
Lecture 8:
Mutex exclusion
Async Completion
The Issue
Accessing shared resources
Fix
Turn off interupts
Avoid shared data
Atomic CPU instructions
Usually never too complex
Can't finish all of critical section with single instruction
Locks
How do we build them?
Acquiring
We need to check if anyone has it
Notify somehow that we now have it
Simple enough where CPU's do offer atomic instruction
Examples
Test and Set
Compare and Swap
Types of Atomicity
Before or After(Ordering)
When we need to wait for some action before we start another.
Like a parent process waiting for its child process until it continues
All or Nothing
When you have a series of instructions you need to run and you can't have it end until all of them are done
An example is updating a shared variable.
Loading the data and altering it must be done fully or none at all
Imagine if right after the load someone else updates it then it jumps back to our work and we alter it somehow.
That data is no longer reliable since it is in an unpredictable state
Waiting/Spins
What to do when you need to wait?
Spin
This means repeatedly check until available
Simple but it's downside is that it does nothing else until it's ready
Good to use when
Not many people will be using the same lock(
low contention
)
Operation time is guaranteed to be short
Waiting doesn't cause other operations to delay(Not sure how but book mentioned this)
Async Wait
Idea
If the lock isn't available ask the CPU to put you to slepe and wake you up when it is
We use
conditional variables
for this
Implementation
Ready Queue
We have a queue of tasks that are waiting, once available we go through the queue to wake things up
Issue: Might not wake the right thread/process
Ideally we'd have a conditional variable for each completion event