atomic-rs
atomic-rs copied to clipboard
Ensure sequential consistency in fallback implementation when requested
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.
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.
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.