[concurrency-interest] Concurrent stack

Dimitris Andreou jim.andreou at gmail.com
Thu Jan 22 17:56:56 EST 2009

Out of curiosity: could the following have a chance to scale better than 
a plain LinkedBlockingDeque? (Modest implementation of concurrent stack, 
from what I read at The Art of Multiprocessor Programming, section 11.3, 
where pending pushes and pops cancel each other).

public class Stack<T> {
    private final BlockingDeque<T> stack = new LinkedBlockingDeque<T>();
    private final SynchronousQueue<T> eliminationQueue = new 

    public void push(T element) throws InterruptedException {
//(I added wait for 1 nanosecond because 0 is special cased and never 
waits, but somebody would have to wait for it to succeed).
        if (eliminationQueue.offer(element, 1L, TimeUnit.NANOSECONDS)) {

    public T pop() throws InterruptedException {
        T element = eliminationQueue.poll(1L, TimeUnit.NANOSECONDS);
        if (element != null) {
            return element;
        return stack.takeLast();

O/H Guy Korland έγραψε:
> Hi,
> Are there any plans to add the concurrent package a concurrent stack?
> The current implementation exists as part of the JRE is a synchronized.
> While there're few well known algorithms for non-blocking stack.
> -- 
> Guy Korland
> ------------------------------------------------------------------------
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list