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

后端 未结 1 846
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 10:40

The new c++ standard introduces the notion of a memory model. There were already questions on SO about it, what does it mean, how does it change the way we write code in c++ and

相关标签:
1条回答
  • 2021-01-30 11:09

    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 memory ordering for reads, std::memory_order_release ordering for writes, and std::memory_order_acq_rel ordering for RMW operations.

    There is no equivalent in Java to std::memory_order_relaxed, or std::memory_order_seq_cst.

    0 讨论(0)
提交回复
热议问题