Home  >  Q&A  >  body text

java内存模型的happens-before语义顺序问题

注意,两个操作之间具有 happens-before 关系,并不意味着前一个操作必须要在后一个操作之前执行!happens-before 仅仅要求前一个操作(执行的结果)对后 一个操作可见,且前一个操作按顺序排在第二个操作之前(the first is visible to and ordered before the second)。happens- before 的定义很微妙,后文会具 体说明 happens-before 为什么要这么定义。

——引用自《深入理解JAVA内存模型》

这本书后边有一个重排序的例子,说明没有依赖关系的两个语句可以重排,所以“并不意味着前一个操作必须要在后一个操作之前执行”。那“且前一个操作按顺序排在第二个操作之前”这句话的含义又是什么呢

黑色斜体两段字所要表明的意思区别究竟在哪,感觉这两句话是矛盾的呢?能否举例说明一下

高洛峰高洛峰2743 days ago721

reply all(1)I'll reply

  • 迷茫

    迷茫2017-04-18 10:54:10

    You can understand it the other way around. hf refers to two instructions in physical order. The first is visible to the second, but it does not necessarily mean that the first one is executed first, not necessarily, because a retake may occur. One item may not be executed first

    reply
    0
  • Cancelreply