Can a Java Compiler or JVM swap instruction order of independent instructions?

Let's take following statements: int d0, d1; int[] ds = {0, 0}; Now one thread has following instructions: d0++; d1++; while the other thread has this instruction: ds[1] = d1; ds[0] = d0; If we run these threads in parallel, there are obviously three combinations that `ds` can look like: {0, 0}, {1, 1}, and {1, 0}. Now the big question is: Can there also be {0, 1}? Can the Compiler/JVM simply swap instruction because it thinks they are unrelated? If yes, what exactly are the "rules" for such behaviour and is it up to the compiler or the JVM?
Usually optimizations are considered safe if they behave the same as the unoptimized code in a serial (iow, one thread) model. Unless the relevant language constructs have explicit provisions for threading

以上就是Can a Java Compiler or JVM swap instruction order of independent instructions?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏