Going through the comments provides another datapoint for what I have observed as an ironclad law: the first version of any code involving tricky atomics and synchronization is always wrong. Reasoning about these things is hard for human brains.<p>I strongly recommend using tools when viable. In Rust a particularly easy-to-use and effective one is loom[1]. Alloy is another good tool that scales well but requires investment. In some cases like the Vulkan memory model, Alloy files are available[2].<p>[1]: <a href="https://docs.rs/loom/latest/loom/" rel="nofollow">https://docs.rs/loom/latest/loom/</a><p>[2]: <a href="https://github.com/KhronosGroup/Vulkan-MemoryModel">https://github.com/KhronosGroup/Vulkan-MemoryModel</a>