atomic-rs icon indicating copy to clipboard operation
atomic-rs copied to clipboard

Ensure sequential consistency in fallback implementation when requested

Open taylordotfish opened this issue 10 months ago • 2 comments

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.

taylordotfish avatar Sep 28 '23 01:09 taylordotfish

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.

Amanieu avatar Sep 29 '23 14:09 Amanieu

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.

taylordotfish avatar Jan 27 '24 21:01 taylordotfish