Unit 2c - Synchronization

Synchronization

Communicating Through Shared Data

The Importance of Mutual Exclusion


 
 
 

Notice: ​ It does work if we say uthread_init(1) ​ But it does not work with uthread_init(2) or higher


Mutual Exclusion Using Locks

 
 

Implementing Simple Locks

Atomic Memory Exchange Instruction

NameSemanticsAssembly
atomic exchanger[v] ← m[r[a]]
m[r[a]] ← r[v]
xchg (ra), rv

Spinlock

Implementing Atomic Exchange

Blocking Locks

Blocking vs Busy Waiting

Video Playback System Example

Monitors and Condition Variables

UThreads Mutex and Condition

 

Video Playback

 
 

Using Conditions

Video Playback (Pause on Empty)

Drinking Beer Example

Signal and Monitor Race

Extending the Example

Using Condition Variables for Disk REad

Why Must Mutex be held when Calling Wait?

 
 

Wait-Signal Race

Wait-Signal Race … Again

You Have to Signal Every Time

Reader-Writer Monitors

Semaphores

UThread Semaphores

 

Using Semaphores to Drink Beer

 

Using Semaphores to Implement Monitors

Hiding Asynchrony

Queue

Ordering Two Threads

One Thread Waits for Many Threads

Synchronization in Java

Java AtomicReference<V> Class

Lock-Free Atomic Stack in Java

 

 

Problems with Concurrency

Mutexes and Recursion

 
 

Systems with Multiple Mutexes

Waiter Graph Can Show Deadlocks

Synchronization Summary

Spinlock

Monitors and Condition Variables

Semaphores

Problems, problems, problems