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

Ensure sequential consistency in fallback implementation when requested #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

taylordotfish
Copy link

As discussed in #37, use Ordering::SeqCst when unlocking the spinlock if the corresponding atomic operation had a requested ordering of SeqCst. Otherwise, the existing Release ordering should be fine. The lock operation can remain unconditionally Acquire; it always occurs as part of an “atomic” lock/unlock pair.

@Amanieu
Copy link
Owner

Amanieu commented Sep 29, 2023

GCC's libatomic does things differently: it effectively inserts a fence(SeqCst) both before acquiring the lock and after releasing it.

I am not completely sure which approach is the correct one.

Use `SeqCst` for both acquiring and releasing the spinlock when the
corresponding atomic operation is `SeqCst`. This may not be strictly
necessary, but it can't hurt.
@taylordotfish
Copy link
Author

Well, I should probably trust GCC's developers' understanding of atomics more than my own, and in any case, the extra assurance can't hurt, so I've modified the PR to acquire the lock with SeqCst when appropriate, as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants