Skip to content

atomic_load in while loop #8

@JackDrogon

Description

@JackDrogon

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));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions