Change volatile recordings using non-volatile recordings

Are volatile recordings with unstable recordings stored?
For Ex:
I have two streams T1 and T2:

T1:

i = 10;  
volatile boolean result = true;

T2:

while(!result){
}

System.out.println(i);

Does T2 always update the value i (10) or the old value?

+4
source share
2 answers

Yes. For a volatile operator, there is a relationship between events and events:

Please think about this stackoverflow question: Are volatile variables the variables of previously imposed relationships before they are read?

- . , .

3.1.3 ( ) "Java Concurrency ". , , :

- ; . , , .

-

+2

, , , 10 .

, , . , . ​​

i = 10 result = true. result = true , result 2. result System.out.println(i);. i = 10 System.out.println(i);.

+1

All Articles