Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] ordering in stack push for maintaining invariant #961

Closed
GWS0428 opened this issue Jun 10, 2024 · 1 comment
Closed

[Question] ordering in stack push for maintaining invariant #961

GWS0428 opened this issue Jun 10, 2024 · 1 comment
Assignees
Labels
lecture question/discussion related to lectures question Further information is requested

Comments

@GWS0428
Copy link

GWS0428 commented Jun 10, 2024

Hello,

The lecture slide points out the following invariant

Invariant: head’s pointer value has release view ⊒ (>= for each loc.)
the messages of all node’s value & next pointer

For maintaining that invariant, I think it is necessary to use load Acquire ordering in stack push method.

    loop {
            let head = self.head.load(Relaxed, &guard);
            n.next = head.as_raw();

            match self
                .head
                .compare_exchange(head, n, Release, Relaxed, &guard)
            {
                Ok(_) => break,
                Err(e) => n = e.new,
            }

            // Repin to ensure the global epoch can make progress.
            guard.repin();
        }

without using Acquire, it seems impossible to get the head's release view and store the updated view into the new head. Could you explain why it is correct to use Relaxed ordering in "self.head.load(Relaxed, &guard);" part?

@GWS0428 GWS0428 added the question Further information is requested label Jun 10, 2024
@kingdoctor123
Copy link
Member

If the CAS on head succeeds, then release view of previous head is automatically included in the new message due to release sequence. As a result, you don't need to acquire the release view when you execute let head = slef.head.load(Relaxed, &guard);. You can see more information on p.115 of the lecture slide.

@kingdoctor123 kingdoctor123 added the lecture question/discussion related to lectures label Jun 10, 2024
@GWS0428 GWS0428 closed this as completed Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lecture question/discussion related to lectures question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants