Does volatile influence non-volatile variables?

前端 未结 4 1820
盖世英雄少女心
盖世英雄少女心 2021-02-20 14:11

Okay, suppose I have a bunch of variables, one of them declared volatile:

int a;
int b;
int c;
volatile int v;

If one thread writes to all four

4条回答
  •  囚心锁ツ
    2021-02-20 14:40

    Yes. volatile, locks, etc., setup the happens-before relationship, but it affects all variables (in the new Java Memory Model (JMM) from Java SE 5/JDK 1.4). Kind of makes it useful for non-primitive volatiles...

提交回复
热议问题