ArticleslgStudy

science

Non-blocking linked list

Non-blocking linked list is a 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 Non-blocking linked list rather than just read about it. In short: A non-blocking linked list is an example of non-blocking data structures designed to implement a linked list in shared memory using synchronization primitives: Compare-and-swap Fetch-and-add Load-link/store-conditional Several strategies for implementing non-blocking lists have been suggested. Review: linked lists (Singly) linked lists are fundamental data structures that are widely used as is, or to build other dat…

Non-blocking linked list — main illustration
Non-blocking linked list — illustration

Key takeaways

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

Reference excerpt

A non-blocking linked list is an example of non-blocking data structures designed to implement a linked list in shared memory using synchronization primitives:

Compare-and-swap Fetch-and-add Load-link/store-conditional Several strategies for implementing non-blocking lists have been suggested.

Review: linked lists (Singly) linked lists are fundamental data structures that are widely used as is, or to build other data structures. They consist of "nodes", or "links", that are put in some order indicated by a "next" pointer on each node. The last node in the list (the "tail") has a nil next pointer. The first node (the "head") is a sentinel: it stores no interesting information and is only used for its next pointer. The operations that must be supported on lists are as follows.

Given a node n that is not yet part of the list, and a pointer p to a node in the list (perhaps the head), insert n after p. Given a pointer p, delete p.next from the list. Both operations must support concurrent use: two or more threads of execution must be able to perform insertions and deletions without interfering with each other's work (see diagram).

Harris's solution

In a 2001 paper, Harris gives a solution to concurrent maintenance of ordered linked list that is non-blocking, using a compare-and-swap (cas) primitive. Insertion of n after p is simple:

next ← p.next n.next ← next cas(address-of(p.next), next, n) If the cas was not successful, go back to 1. Deletion of p.next is more involved. The naive solution of resetting this pointer with a single CAS runs the risk of losing data when another thread is simultaneously inserting (see diagram). This is specific case of the ABA problem. Instead, two invocations of cas are needed for a correct algorithm. The first marks the pointer p.next as deleted, changing its value but in such a way that the original pointer can still be reconstructed. The second actually deletes the node by resetting p.next.

Operations on lock-free linked lists

Insert search for the right spot in the list insert using Compare-and-swap

Delete (Naive approach) search for the right spot in the list delete using Compare-and-swap

Contains search for a specific value in the list and return whether it is present or not this is a read only operation, does not pose any concurrency issues

Problems

Concurrent insert and delete a process deleting node B requires an atomic action on the node's predecessor concurrently another process tries to insert a node C after node B (B.next=C) node B is deleted from the list but C is gone along with it

Solutions Harris place a 'mark' in the next pointer of the soon-to-be deleted node fail when we try to CAS the 'mark' when detected go back to start of the list and restart Zhang et al. search the list to see if the value to be deleted exists, if exists mark the node logically deleted a subsequent traversal of the list will do garbage collection of logically deleted nodes

Concurrent deletions two processes concurrently delete an adjacent node: node B and node C respectively the delete of node C is undone by the delete of node B

Solutions Valois

make use of auxiliary nodes which contain only a next field each regular node must have an auxiliary node as its predecessor and successor deletion will result in an extra auxiliary node being left behind, which means the delete will have to keep trying to clean up the extra auxiliary nodes use an extra 'back_link' field so the delete operation can traverse back to a node that has not been deleted from the list

Further reading High Performance Dynamic Lock-Free Hash Tables and List-Based Sets, Maged M. Michael Fomitchev, Mikhail; Ruppert, Eric (2004). Lock-free linked lists and skip lists (PDF). Proc. Annual ACM Symp. on Principles of Distributed Computing (PODC). pp. 50–59. doi:10.1145/1011767.1011776. ISBN 1581138024. Two-handed emulation: how to build non-blocking implementations of complex data-structures using DCAS, Michael Greewald Highly-Concurrent Multi-word Synchronization, Hagit Attiya, Eshcar Hillel Lock-free deques and doubly linked lists, Håkan Sundell, Philippas Tsigas

References

Worked examples

Example 1 — a first encounter with Non-blocking linked list

Start with the simplest possible case. Write down what Non-blocking linked list claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In 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 Non-blocking linked list 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 Non-blocking linked list 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 Non-blocking linked list

In research
Non-blocking linked list appears in 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 Non-blocking linked list 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
Non-blocking linked list is common in secondary-school and first-year university syllabi. It links to neighbouring topics Linked lists, so understanding it makes those chapters shorter.
In everyday life
Look for Non-blocking linked list 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.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Non-blocking linked list in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Non-blocking linked list 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 Non-blocking linked list out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Non-blocking linked list in simple terms?

A non-blocking linked list is an example of non-blocking data structures designed to implement a linked list in shared memory using synchronization primitives: Compare-and-swap Fetch-and-add Load-link/store-conditional Several strategies for implementing non-blocking lists have been suggested. Revi…

Why does Non-blocking linked list matter?

Because it connects several 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 Non-blocking linked list?

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 Non-blocking linked list.

Tags

  • Linked lists

Keep exploring