For example, in the standards C11 and C++11, features 6 types of memory barriers: http://en.cppreference.com/w/cpp/atomic/memory_order
- memory_order_relaxed
- memory_order_consume
- memory_order_acquire
- memory_order_release
- memory_order_acq_rel
- memory_order_seq_cst
Which are determine the directions in which the compiler can reorder instructions, as well as which of processor instructions requires to insert to limit reordering in pipeline of processor.
For example, the first five barriers affect only the compiler , but does not generate any CPU instructions (no S/L/ MFENCE
), because in x86 - acquire-release-semantics is provided automatically .
How many types of memory barriers available in Java? Or is there only 2 types?
- All reordering allowed
- All reordering prohibited