Ordering::SeqCst

Finally, and on the opposite side of the spectrum from Relaxed, there is SeqCst, which stands for SEQuentially ConsiSTent. SeqCst is like AcqRel but with the added bonus that there's a total order across all threads between sequentially consistent operations, hence the name. SeqCst is a pretty serious synchronization primitive and one that you should use only at great need, as forcing a total order between all threads is not cheap; every atomic operation is going to require a synchronization cycle, for whatever that means for your CPU. A mutex, for instance, is an acquire-release structure—more on that shortly—but there are legitimate cases for a super-mutex like SeqCst. For one, implementing older papers. In the early days ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.