Synchronization mode in a mutex-protected block
http://www.boost.org/doc/libs/1_58_0/doc/html/atomic/usage_examples.html
In the "Singleton with double-checked locking pattern" example of the above acceleration examples: memory_order_consume for the second loadable _instance value and memory_order_release for storing _instance? I thought scoped_lock already has semantics and frees semantics, and the first load of _instance has a memory_order_consume sync mode.
source to share
Assuming the primitives used here boost
support the same functionality as their equivalents std
, the second is load
not required memory_order_consume
as it is guaranteed to sync with store/release
based on get / release semantics mutex
, you are correct about that.
Perhaps the use memory_order_consume
was based on the false assumption that a load/relaxed
could float through the barrier, mutex/acquire
but this is not guaranteed mutex
, and as such is memory_order_relaxed
excellent.
On the other hand, it is store/release
absolutely necessary as it syncs with the first one load/consume
, which is not secure mutex
.
source to share