根据the Java Memory Model (JMM):
当且仅当所有顺序一致的执行都没有数据竞争时,一个程序才是correctly synchronized.
如果程序被正确同步,则该程序的所有执行将看起来是顺序一致的(§17.4.3).
I don't see how the the fact that no SC execution has data races guarantees that every execution has no data races (which means that every execution is SC).
Is there a proof of that?
我发现:
-
A blog post by Jeremy Manson (one of the authors of the JMM).
The following paragraph might mean that the guarantee is provided by causality (but I don't see how):因此,这个模型背后有一种直觉.如果要证明读操作返回写操作的值这一事实是合理的,则可以在以下情况下执行此操作:
a) That write happened before it, or
b) You have already justified the write.该模型的工作方式是,从具有属性a)的所有操作都合理的执行开始,然后开始迭代地调整操作.因此,在上面的第二个示例中,您创建的连续执行证明了0、2、3、4、1的合理性.
这一定义的可爱之处在于,它相当直观,也保证了DRF节目的SC.
-
Foundations of the C++ Concurrency Memory Model.
This article describes C++ memory model (which has similarities with the JMM).
Section 8 of the article has a proof of a similar guarantee for C++:定理8.1.If a program allows a type 2 data race in a consistent execution, then there exists a sequentially consistent execution, with two conflicting actions, neither of which happens before the other.8
In effect, we only need to look at sequentially consistent executions in order to determine whether there is a data race in a consistent execution.
[...]
8 The latter is essentially the condition used in [25] to define “correctly synchronized” for Java.不幸的是,我不确定这一证明是否适用于JMM,因为以下情况不起作用:
考虑<T中不包含数据竞争的最长前缀P.请注意,P中的每个加载必须看到一个存储,该存储在同步或发生之前的顺序中位于它之前.
在我看来,上述情况在JMM中不起作用,因为因果关系允许读操作返回稍后的存储.