What is volatile variable?

volatile is a keyword to indicate compiler that the variable it is used with should not be assumed to be unchanged during the course of execution of the code. Most compilers do optimizations which assumes that variable will not be changed until software is changing it. Refer following piece of code to understand it further:

int count = 10;
if(count < 20) {
//do something
}

In this code, compiler can not remove if check for optimization. The value of count can be changed between assignment and if check by some other process.

Related Post

Installing Apache Ant in Windows
Starting tomcat in debug mode – Linux
What is semaphore?
Installing JDK in ubuntu/linux
Converting Array to List

Comments

Leave a Reply




Technology