Big problems with lock free

ABA problem

T1 reads a shared value as A then sleeps. While T1 sleeps, T2 changes the shared value to B then back to A. T1 later wakes up and still sees value as A.

cannot differ between “unchanged” or “changed and reverted”

Time-to-use problem

many data structures may contain the following snippet:

Node *current = x.head(); // assume the load from "x.head()" is atomic
Node *next = current.next(); // assume this load is also atomic

It may happen that:

T1: current = x.head()
T2: delete current
T1: next = current.next() // current is already deleted!!!

Hazard pointer

C++ 26 adds std hazard_pointer

To avoid 2 big problems: each thread stores a list of hazard pointers or pointers that the thread is current reading/using. Other threads must not modify the underlying object. Deleting the object must be delayed until all threads finish using it.

Read Copy Update

C++ 26 adds std rcu

SPSC queue