[英]Sequentially consistent memory and atomic registers
Sequential Consistency (for data race free programs, SC-DRF) is the strongest shared memory consistency model provided by modern programming languages (eg, Java or C++11). 顺序一致性 (对于无数据争用程序,SC-DRF)是现代编程语言(例如Java或C ++ 11)提供的最强的共享内存一致性模型。
In ''Art of Multiprocessor Programming'' the authors (M. Herlihy and N. Shavit) use notion of atomic register in most of the theorems throughout the book. 在《多处理器编程的艺术》一书中,作者(M. Herlihy和N. Shavit)在整本书的大多数定理中都使用了原子配准的概念。
Is it correct to say that volatile
references in Java and atomics with std::memory_order seq_cst
in C++ are (indistinguishable from) atomic registers? 是否正确地说Java和C ++中具有std::memory_order seq_cst
原子的volatile
引用是原子寄存器(无法区别)? Is it possible to observe difference between linearizable registers and atomics in C++ if its memory model guarantees sequential consistency on whole space of memory locations marked as std::atomic
? 如果C ++的内存模型保证标记为std::atomic
的内存位置的整个空间上的顺序一致性,是否有可能观察到C ++中线性化寄存器与原子之间的区别?
For the C/C++ case, atomics read or modified with memory_order_seq_cst should give you everything you're looking for (atomic RMW operations, and linearizability is guaranteed.) 对于C / C ++情况,使用memory_order_seq_cst读取或修改的原子应该为您提供所需的一切(原子RMW操作,并保证了线性化)。
For java, volatile gives you linearizability of reads and writes but any serious concurrent code is probably going to want RMW (ie compare and swap) too, so look into the java Atomic package for types that also do compare and swap (I think it is not possible to achieve compare and swap yourself without using these packages or using the synchronized keyword) http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/package-summary.html 对于Java,volatile可以为您提供读写的线性化能力,但是任何严肃的并发代码也可能也需要RMW(即比较和交换),因此,请查看java Atomic包中也可以进行比较和交换的类型(我认为这是如果不使用这些程序包或使用synced关键字,则无法实现比较和交换自己) http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/package-summary.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.