Treiber stack
The Treiber stack algorithm is a scalable lock-free stack utilizing the fine-grained concurrency primitive compare-and-swap. It is believed that R. Kent Treiber was the first to publish it in his 1986 article "Systems Programming: Coping with Parallelism".
The Treiber stack algorithm is a scalable lock-free stack utilizing the fine-grained concurrency primitive compare-and-swap. It is believed that R. Kent Treiber was the first to publish it in his 1986 article "Systems Programming: Coping with Parallelism". ==Basic principle== The basic principle for the algorithm is to only add something new to the stack when the item to add is verified to be the only thing that has been added since the operation began. This is done by using compare-and-swap. Pushing an item to the stack is done by first taking the top of the stack (old head) and placing it after the new item to create a new head. The old head is then compared to the current head. If the two match then the old head can be swapped to the new one; if not, then it means another thread has added an item to the stack, in which case another attempt is necessary. When popping an item from the stack, before returning the item it must be verified that another thread has not added a new item since the operation began. ==Java example== Below is an implementation of the Treiber Stack in Java, based on the one provided by book Java Concurrency in Practice. import java.util.concurrent.atomic.*; import net.jcip.annotations.*; /** * ConcurrentStack * * Nonblocking stack using Treiber's algorithm * * @author Brian Goetz and Tim Peierls */ @ThreadSafe public class ConcurrentStack { AtomicReference > top = new AtomicReference >(); public void push(E item) { Node newHead = new Node (item); Node oldHead; do { oldHead = top.get(); newHead.next = oldHead; } while (!top.compareAndSet(oldHead, newHead)); } public E pop() { Node oldHead; Node newHead; do { oldHead = top.get(); if (oldHead == null) return null; newHead = oldHead.next; } while (!top.compareAndSet(oldHead, newHead)); return oldHead.item; } private static class Node { public final E item; public Node next; public Node(E item) { this.item = item; } } } ==References==
References
- Hendler, D., Shavit, N. and Yerushalmi, L., 2004, June. A scalable lock-free stack algorithm. In Proceedings of the sixteenth annual ACM symposium on Parallelism in algorithms and architectures (pp. 206-215). ACM. Wikipedia revision 1378756203, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1378756203
Cite this reference
MLA "Hendler, D., Shavit, N. and Yerushalmi, L., 2004, June. A scalable lock-free stack algorithm. In Proceedings of the sixteenth annual ACM symposium on Parallelism in algorithms and architectures (pp. 206-215). ACM. Wikipedia revision 1378756203, retrieved 2026-11-18." Hendler, D. 2026-11-17. https://en.wikipedia.org/w/index.php?oldid=1378756203. Accessed 24 November 2026.
Chicago "Hendler, D., Shavit, N. and Yerushalmi, L., 2004, June. A scalable lock-free stack algorithm. In Proceedings of the sixteenth annual ACM symposium on Parallelism in algorithms and architectures (pp. 206-215). ACM. Wikipedia revision 1378756203, retrieved 2026-11-18." Hendler, D. 2026-11-17. https://en.wikipedia.org/w/index.php?oldid=1378756203.
APA Hendler, D. (2026). Hendler, D., Shavit, N. and Yerushalmi, L., 2004, June. A scalable lock-free stack algorithm. In Proceedings of the sixteenth annual ACM symposium on Parallelism in algorithms and architectures (pp. 206-215). ACM. Wikipedia revision 1378756203, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1378756203
- Treiber, R.K., 1986. Systems programming: Coping with parallelism. International Business Machines Incorporated, Thomas J. Watson Research Center. Wikipedia revision 1378756203, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1378756203
Cite this reference
MLA "Treiber, R.K., 1986. Systems programming: Coping with parallelism. International Business Machines Incorporated, Thomas J. Watson Research Center. Wikipedia revision 1378756203, retrieved 2026-11-18." Treiber, R. 2026-11-17. https://en.wikipedia.org/w/index.php?oldid=1378756203. Accessed 24 November 2026.
Chicago "Treiber, R.K., 1986. Systems programming: Coping with parallelism. International Business Machines Incorporated, Thomas J. Watson Research Center. Wikipedia revision 1378756203, retrieved 2026-11-18." Treiber, R. 2026-11-17. https://en.wikipedia.org/w/index.php?oldid=1378756203.
APA Treiber, R. (2026). Treiber, R.K., 1986. Systems programming: Coping with parallelism. International Business Machines Incorporated, Thomas J. Watson Research Center. Wikipedia revision 1378756203, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1378756203
- J.F. Groote and M.R. Mousavi. Modeling and analysis of communicating systems. The MIT Press 2014. Wikipedia revision 1378756203, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1378756203
Cite this reference
MLA "J.F. Groote and M.R. Mousavi. Modeling and analysis of communicating systems. The MIT Press 2014. Wikipedia revision 1378756203, retrieved 2026-11-18." J. 2026-11-17. https://en.wikipedia.org/w/index.php?oldid=1378756203. Accessed 24 November 2026.
Chicago "J.F. Groote and M.R. Mousavi. Modeling and analysis of communicating systems. The MIT Press 2014. Wikipedia revision 1378756203, retrieved 2026-11-18." J. 2026-11-17. https://en.wikipedia.org/w/index.php?oldid=1378756203.
APA J. (2026). J.F. Groote and M.R. Mousavi. Modeling and analysis of communicating systems. The MIT Press 2014. Wikipedia revision 1378756203, retrieved 2026-11-18. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1378756203
- Jcip.net. (2016). [online] Available at: http://jcip.net/listings/ConcurrentStack.java [Accessed 13 May 2016] Wikipedia revision 1378756203, retrieved 2026-11-18 · retrieved 2026-11-17 · rev 1378756203
Cite this reference
MLA "Jcip.net. (2016). [online] Available at: http://jcip.net/listings/ConcurrentStack.java [Accessed 13 May 2016] Wikipedia revision 1378756203, retrieved 2026-11-18." Jcip. 2026-11-17. http://jcip.net/listings/ConcurrentStack.java. Accessed 24 November 2026.
Chicago "Jcip.net. (2016). [online] Available at: http://jcip.net/listings/ConcurrentStack.java [Accessed 13 May 2016] Wikipedia revision 1378756203, retrieved 2026-11-18." Jcip. 2026-11-17. http://jcip.net/listings/ConcurrentStack.java.
APA Jcip. (2026). Jcip.net. (2016). [online] Available at: http://jcip.net/listings/ConcurrentStack.java [Accessed 13 May 2016] Wikipedia revision 1378756203, retrieved 2026-11-18. Retrieved November 24, 2026, from http://jcip.net/listings/ConcurrentStack.java
Cite this article
MLA
"Treiber stack." encyclopegia.org, 2026, https://encyclopegia.org/wiki/treiber-stack. Accessed 24 November 2026.
Chicago
"Treiber stack." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/treiber-stack.
APA
encyclopegia.org. (2026). Treiber stack. Retrieved November 24, 2026, from https://encyclopegia.org/wiki/treiber-stack
Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON