Concurrent Queues and Stacks
The Five-Fold Path
Another Fundamental Problem
Queues & Stacks
Queues
Stacks
Bounded
Unbounded
Blocking
Blocking
Non-Blocking
This Lecture
Queue: Concurrency
Concurrency
Bounded Queue
Bounded Queue
Bounded Queue
Bounded Queue
Not Done Yet
Not Done Yet
Not Done Yet
Enqueuer
Enqueuer
Enqueuer
Enqueuer
Enqueuer
Enqueuer
Enqueuer
Unsuccesful Enqueuer
Dequeuer
Dequeuer
Dequeuer
Dequeuer
Dequeuer
Dequeuer
Unsuccesful Dequeuer
Bounded Queue
Bounded Queue
Digression: Monitor Locks
The Java Lock Interface
The Java Lock Interface
The Java Lock Interface
The Java Lock Interface
The Java Lock Interface
Lock Conditions
Lock Conditions
Lock Conditions
Lock Conditions
Await
Signal
Signal All
A Monitor Lock
Unsuccessful Deq
Another One
Enqueuer to the Rescue
Monitor Signalling
Dequeuers Signalled
Dequeuers Signaled
Dollar Short + Day Late
Java Synchronized Methods
Java Synchronized Methods
Java Synchronized Methods
Java Synchronized Methods
Java Synchronized Methods
(Pop!) The Bounded Queue
Bounded Queue Fields
Bounded Queue Fields
Bounded Queue Fields
Bounded Queue Fields
Enq Method Part One
Enq Method Part One
Enq Method Part One
Enq Method Part One
Be Afraid
Enq Method Part One
Enq Method Part One
Beware Lost Wake-Ups
Lost Wake-Up
Lost Wake-Up
Lost Wake-Up
What’s Wrong Here?
Solution to Lost Wakeup
Enq Method Part Deux
Enq Method Part Deux
Enq Method Part Deux
Enq Method Part Deux
The Enq() & Deq() Methods
Split the Counter
Split Counter
A Lock-Free Queue
Compare and Set
Enqueue
Enqueue
Logical Enqueue
Physical Enqueue
Enqueue
Enqueue
When CASs Fail
Dequeuer
Dequeuer
Memory Reuse?
Dequeuer
Simple Solution
Why Recycling is Hard
Both Nodes Reclaimed
One Node Recycled
Why Recycling is Hard
Recycle FAIL
The Dreaded ABA Problem
Dreaded ABA continued
Dreaded ABA continued
Dreaded ABA continued
The Dreaded ABA FAIL
Dreaded ABA – A Solution
Atomic Stamped Reference
Concurrent Stack
Empty Stack
Push
Push
Push
Push
Push
Push
Push
Pop
Pop
Pop
Pop
Pop
Lock-free Stack
Lock-free Stack
Lock-free Stack
Lock-free Stack
Lock-free Stack
Lock-free Stack
Lock-free Stack
Lock-free Stack
Lock-free Stack
Big Question
Elimination-Backoff Stack
Observation
Idea: Elimination Array
Push Collides With Pop
No Collision
Elimination-Backoff Stack
Elimination-Backoff Stack
Dynamic Range and Delay
Linearizability
Un-Eliminated Linearizability
Eliminated Linearizability
Backoff Has Dual Effect
Elimination Array
Elimination Array
Digression: A Lock-Free Exchanger
A Lock-Free Exchanger
Atomic Stamped Reference
Extracting Reference & Stamp
Extracting Reference & Stamp
Exchanger Status
Exchanger Status
Exchange Status
Exchange Status
The Exchange
The Exchange
The Exchange
The Exchange
The Exchange
The Exchange
Lock-free Exchanger
Lock-free Exchanger
Lock-free Exchanger
Lock-free Exchanger
Lock-free Exchanger
Lock-free Exchanger
Lock-free Exchanger
Exchanger State EMPTY
Exchanger State EMPTY
Exchanger State EMPTY
Exchanger State EMPTY
Exchanger State EMPTY
Exchanger State EMPTY
Exchanger State EMPTY
Exchanger State EMPTY
States WAITING and BUSY
States WAITING and BUSY
States WAITING and BUSY
States WAITING and BUSY
The Exchanger Slot
Back to the Stack: the Elimination Array
Elimination Array
Elimination Array
Elimination Array
Elimination Stack Push
Elimination Stack Push
Elimination Stack Push
Elimination Stack Push
Elimination Stack Push
Elimination Stack Push
Elimination Stack Pop
Elimination Stack Pop
Summary