ArticleslgStudy

computer science

Treiber stack

Treiber stack is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Treiber stack rather than just read about it. In short: The Treiber stack algorithm is a scalable lock-free stack utilizing the fine-grained concurrency primitive compare-and-swap. It is believed that R.

Key takeaways

  • Treiber stack belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Treiber stack to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Treiber stack from memory before moving on to harder problems.

Reference excerpt

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.

Correctness Some implementations of the Treiber stack—particularly, those in languages without garbage collection—can be at risk for the ABA problem. When a process is about to remove an element from the stack (just before the compare-and-swap in the pop routine below) another process can change the stack such that the head is the same, but the second element is different. The compare-and-swap will set the head of the stack to the old second element in the stack, mixing up the complete data structure. Implementations in languages with garbage collection where new elements are allocated for each push (as in the Java implementation below) do not suffer such problems since the old head remains reachable from the process performing the compare-and-swap, and thus cannot be reclaimed and reused by another process pushing a new element to the stack as above. Testing for failures such as ABA can be exceedingly difficult, because the problematic sequence of events is very rare. Model checking is an excellent way to uncover such problems. See for instance exercise 7.3.3 in "Modeling and analysis of communicating Systems".

Java example Below is an implementation of the Treiber Stack in Java, based on the one provided by book Java Concurrency in Practice.

References

Worked examples

Example 1 — a first encounter with Treiber stack

Start with the simplest possible case. Write down what Treiber stack claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Treiber stack before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Treiber stack ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Treiber stack

In research
Treiber stack appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Treiber stack in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Treiber stack is common in secondary-school and first-year university syllabi. It links to neighbouring topics Concurrent computing, so understanding it makes those chapters shorter.
In everyday life
Look for Treiber stack outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Treiber stack” →

How to study Treiber stack in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Treiber stack means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Treiber stack out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Treiber stack in simple terms?

The Treiber stack algorithm is a scalable lock-free stack utilizing the fine-grained concurrency primitive compare-and-swap. It is believed that R.

Why does Treiber stack matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Treiber stack?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Treiber stack.

Tags

  • Concurrent computing

Keep exploring