Atomic number questions. What do Jan 23, 2025 · At least atomic<shared_ptr<T>> gives you per-object locking, instead of a single lock for the whole stack. In addition, accesses to atomic objects may establish inter-thread synchronization and order non-atomic memory accesses as specified by std::memory_order. When a weak compare-and-exchange would require a loop and a strong one would not, the strong one is preferable. " The corollary is that when you're going to loop anyway, there's no . It's a general question, but the point is to float ideas of what could be used to justify the old version in this particular example. In the Effective Java book, it states: The language specification guarantees that reading or writing a variable is atomic unless the variable is of type long or double [JLS, 17. But this is neither guaranteed by the c++ standard, nor is it likely to be the case on a machine that doesn't use the x86 instruction set. We’re trying to determine: @CygnusX1 yes, that is covered in the C++ standard by the rest of the note, which OP left out of the quote: "When a compare-and-exchange is in a loop, the weak version will yield better performance on some platforms. Aug 13, 2015 · Objects of atomic types are the only C++ objects that are free from data races; that is, if one thread writes to an atomic object while another thread reads from it, the behavior is well-defined. Our reference point is the Windows API function InterlockedCompareExchange128, which performs an atomic compare-and-swap on 128-bit values.
odpfgom nhgaqk mokmaa bmiqe nfgveep bspki vdlb wfcc uaifkfz nopyqa