orig = atomic_load(head) should be moved to while loop. For example, 2 thread exec static void push(_Atomic struct lstack_head *head, struct lstack_node *node), they both run while loop, the first thread succeed, the second thread's orig will always not equal head, because head is updated by the first thread. So orig = atomic_load(head) should be moved to while loop.
static void push(_Atomic struct lstack_head *head, struct lstack_node *node)
{
struct lstack_head next, orig;
do {
orig = atomic_load(head);
node->next = orig.node;
next.aba = orig.aba + 1;
next.node = node;
} while (!atomic_compare_exchange_weak(head, &orig, next));
}
orig = atomic_load(head)should be moved to while loop. For example, 2 thread execstatic void push(_Atomic struct lstack_head *head, struct lstack_node *node), they both run while loop, the first thread succeed, the second thread's orig will always not equal head, because head is updated by the first thread. Soorig = atomic_load(head)should be moved to while loop.