Can modern x86 hardware not store a single byte to memory?

TL:DR: On every modern ISA that has byte-store instructions (including x86), they’re atomic and don’t disturb surrounding bytes. (I’m not aware of any older ISAs where byte-store instructions could “invent writes” to neighbouring bytes either.) The actual implementation mechanism (in non-x86 CPUs) is sometimes an internal RMW cycle to modify a whole word in a …

Read more

Acquire/Release versus Sequentially Consistent memory order

The C++11 memory ordering parameters for atomic operations specify constraints on the ordering. If you do a store with std::memory_order_release, and a load from another thread reads the value with std::memory_order_acquire then subsequent read operations from the second thread will see any values stored to any memory location by the first thread that were prior …

Read more

What are the similarities between the Java memory model and the C++11 memory model?

The Java memory model was an important influence on the C++11 memory model, and was where we pulled the terms happens-before and synchronizes-with from. However, the C++11 memory model offers much more fine-grained control over memory ordering than the Java memory model. Java volatile variables are equivalent to C++11 std::atomic<> variables, if you use std::memory_order_acquire …

Read more

How do memory_order_seq_cst and memory_order_acq_rel differ?

http://en.cppreference.com/w/cpp/atomic/memory_order has a good example at the bottom that only works with memory_order_seq_cst. Essentially memory_order_acq_rel provides read and write orderings relative to the atomic variable, while memory_order_seq_cst provides read and write ordering globally. That is, the sequentially consistent operations are visible in the same order across all threads. The example boils down to this: bool …

Read more

How do “acquire” and “consume” memory orders differ, and when is “consume” preferable?

Load-consume is much like load-acquire, except that it induces happens-before relationships only to expression evaluations that are data-dependent on the load-consume. Wrapping an expression with kill_dependency results in a value that no longer carries a dependency from the load-consume. The key use case is for the writer to construct a data structure sequentially, then swing …

Read more

What does the [[carries_dependency]] attribute mean?

[[carries_dependency]] is used to allow dependencies to be carried across function calls. This potentially allows the compiler to generate better code when used with std::memory_order_consume for transferring values between threads on platforms with weakly-ordered architectures such as IBM’s POWER architecture. In particular, if a value read with memory_order_consume is passed in to a function, then …

Read more

c++, std::atomic, what is std::memory_order and how to use them?

The std::memory_order values allow you to specify fine-grained constraints on the memory ordering provided by your atomic operations. If you are modifying and accessing atomic variables from multiple threads, then passing the std::memory_order values to your operations allow you to relax the constraints on the compiler and processor about the order in which the operations …

Read more