Answer by Tom Hawtin - tackline for behaviour of volatile keyword in java
Most of the talk is about hardware. Actually compiler optimisations are typically more relevant. You're accessing a field repetitively in a small method, so let's put it in a register. Altering the...
View ArticleAnswer by yshavit for behaviour of volatile keyword in java
In your example, num starts with a default value of 0, and you then (on its declaration line) assign it to 0. That assignment would be a data race if num weren't volatile, but of course you wouldn't be...
View ArticleAnswer by Santosh for behaviour of volatile keyword in java
The effect of volatile variable is evident on multiprocessor system wherein different threads run on different processors. On ordinary single processor system, the impact may not be evident. Here is...
View ArticleAnswer by Edwin Buck for behaviour of volatile keyword in java
The main differences between having a volatile keyword or not is whether you need a memory fence to safely operate with the data.Memory fences prevent side effects that can occur amongst multiple...
View ArticleAnswer by John Vint for behaviour of volatile keyword in java
As per definition of volatile keyword it says, when variable is declared as volatile then thread will directly read/write to variable memory instead of read/write from local thread cache.Not...
View ArticleAnswer by Gray for behaviour of volatile keyword in java
So without the volatile keyword, the threads are just printing the value of num in their local memory cache. Their changes to num are in no way synchronized with the other thread's view of num. I see...
View Articlebehaviour of volatile keyword in java
I need some example on Volatile Keyword of Java Threads.As per definition of volatile keyword it says, when variable is declared as volatile then thread will directly read/write to variable memory...
View Article