When should one use `Relaxed` memory ordering
โ Rust ๐ 2026-02-18 ๐ค surdeus ๐๏ธ 7When I first started learning about atomics, I used to think it was fine to blindly use Relaxed memory ordering if only a single variable was involved. But after thinking about it more, I feel thatโs not actually true...it also depends on what I want to achieve with that atomic variable.
For example, if we need some information (e.g., โplease stopโ) to reach another thread, Relaxed ordering might not be a good choice, right? Since there would be no happens before relationship between the threads (assuming all the joins happen after spawning all the threads), in that case we might want to use Release and Acquire.
The only guarantee we sort of get when using Relaxed is that, after all the atomic operations on a variable are done, we will see what we were expecting, correct?
1 post - 1 participant
๐ท๏ธ Rust_feed