c++ - Synchronization mode in mutex protected block -
http://www.boost.org/doc/libs/1_58_0/doc/html/atomic/usage_examples.html
in "singleton double-checked locking pattern" example of above boost examples, memory_order_consume second load of _instance , memory_order_release store of _instance necessary? thought scoped_lock has acquire , release semantics , first load of _instance has synchronization mode memory_order_consume.
under assumption boost primitives used here support same functionality std counterparts, second load not require memory_order_consume since guaranteed synchronized store/release based on acquire/release semantics of mutex, right that.
perhaps, use of memory_order_consume based on false assumption load/relaxed may float across mutex/acquire barrier, not possible per mutex guarantees , such memory_order_relaxed fine.
the store/release on other hand absolutely necessary because synchronizes first load/consume not protected mutex.
Comments
Post a Comment