neat piece of invisible infrastructure: the Rust portable-atomic crate
your platform doesn’t support a particular type of atomic natively? not a problem, this crate gives you an implementation anyway
how? well there’s a global lock, you see. or, rather, 67 global locks, and which one gets used depends on the address of the atomic mod 67.
but, that’s kinda inefficient, so you wouldn’t want to use it unless it’s your only choice, right?
so they have a bunch of platform specific implementations, such as “let’s detect at runtime if cmpxchg16b is supported” or “this is a microcontroller so if we read it within one instruction we’re fine, and otherwise just disable the interrupts”
and as a result you can just use it and not really think about it, because in 99% of cases it’s gonna do the same thing as what you’d end up with if you bothered to optimize it manually
the ratio of elaborate internals to unassuming API surface is so great here you could easily blink and miss the fact that someone is pulling off heroic feats to make this happen