Multithreaded Concurrent Programming Study Notes 10 (Xiaodi Classroom)----jvm and Concurrency

jvm memory model:

 

 The principle of first occurrence happens-----before

 

 

 Instruction reordering:

 

We write such a piece of code, how many possible results can we guess?
 

There are several possibilities.

 In order to output all kinds of situations, we use an infinite loop to run this code:

 

 

 

 So why does it happen that x and y are both 0?

 Because it may have produced this instruction rearrangement.

Guess you like

Origin blog.csdn.net/weixin_52618349/article/details/130310145