Download presentation
Presentation is loading. Please wait.
1
Scalable lock-free Stack Algorithm
Wael Yehia York University February 8, 2010
2
A scalable lock-free stack algorithm
To reduce contention on the stack (i.e. on the top pointer) we used: Elimination as a Backoff mechanism Example: t1: push(3), t2: pop(), t3: push(1), t4: push(2) All but t4 fail to modify the top pointer So they try to collide: Stack t4 push(2) top top 2 t1, t2, t3 backoff 5 5 t1 t2 t3 1 Collision Array 1
3
Implementation The algorithm is non-blocking so no locks
4 classes created stack<T> AtomicReference<cell<T>> top T pop(threadInfo<T> p) void push(T value, threadInfo<T> p) StackThread threadInfo<T> info threadInfo<T> final int id final int spin OP op cell<T> cell cell<T> cell<T> next T value
4
Key variables We have three shared variables:
two arrays used during collision: void * location[] - for data exchange and synch java.util.concurrent.atomic.AtomicReferenceArray int collision[] - for finding a collision partner java.util.concurrent.atomic.AtomicIntegerArray one top pointer: Cell * top - points to the top of the stack java.util.concurrent.atomic.AtomicReference
5
Correctness Tests Tested for correctness by:
Counting the number of pushes, pops and failed pops Compare the expected stack size to the actual size So far all expected == actual
6
Timing tests Ran the stack under different number of threads and total operations Compared to Treiber’s stack (the one discussed in class) Ours ran 2-3 times faster. The rate increased as # of threads increased
7
Our stack vs Treiber’s
8
Possible improvement and the next step
Will test against: improved implementations of our stack algorithm synchronized stack Try to prove some properties of our algorithm
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.