问题描述
我需要了解在多核机器内存栅栏。说我有这个code
核心1
MOV [_x],1; MOV R1,[_y]
的Core 2
MOV [_y],1; MOV R2,[_x]
现在无记忆栅栏意想不到的结果,将会是既R1和R2可以执行之后为0。在我看来,对付这个问题,我们应该把存储栅栏两个codeS,因为把它只有一个仍然不能解决问题。喜欢的东西如下...
核心1
MOV [_x],1; memory_fence; MOV R1,[_y]
的Core 2
MOV [_y],1; memory_fence; MOV R2,[_x]
我的理解是正确的还是我还是失去了一些东西?假设该架构86。此外,有人可以告诉我怎么把内存栅栏,C ++ code?
栅栏序列,它们围栏(负载&放大器;存储)操作,即,没有任何其他操作可以开始直到围栏被执行,但栅栏不会执行到所有preceding操作完成。引用英特尔使这多一点的precise(从MFENCE指令采取3-628页,第2A,英特尔的指令参考。)的含义是:
Using fences in C++ is tricky (C++11 may have fence semantics somewhere, maybe someone else has info on that), as it is platform and compiler dependent. For x86 using MSVC or ICC, you can use the _mm_lfence
, _mm_sfence
& _mm_mfence
for load, store and load + store fencing (note that some of these are SSE2 instructions).
Note: this assumes an Intel perspective, that is: one using an x86 (32 or 64 bit) or IA64 processor
这篇关于如何内存围栏工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!