Is iinc atomic in Java?

后端 未结 6 998
情话喂你
情话喂你 2020-12-30 12:30

I know increment operation is not atomic in C++ without locking.

Will JVM add any lock on its implementation of iinc instruction?

6条回答
  •  囚心锁ツ
    2020-12-30 13:16

    It is not atomic. Here is the generated byte code for an post-increment of a static int:

    0 getstatic 18;    // Load value of variable.
    3 iconst_1;
    4 iadd;
    5 putstatic 18;    // Store value.
    

提交回复
热议问题