home       edit & win prizes     members     top editors ranking     editors wanted     editor guidelines     contact duno
search:
   my friends   my profile register  login
What Is Volatile Variable 
email chief editor    last edit: 31 December 1969
 edit this article & win cash prizes




there is no article on this topic yet. create one



0 dunos vote up vote down Janya date added 31 Dec 1969 send private message to Janya
In computer programming, a variable or object declared with the volatile keyword may be modified externally from the declaring object. For example, a variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile will not be optimized by the compiler because their value can change at any time. Note that operations on a volatile variable are still not atomic.


[edit] What can happen if volatile is not used?
The following piece of C source code demonstrates the use of the volatile keyword.

void foo(void)
{
int *addr;
addr = 100;

*addr = 0;

while (*addr != 255)
;
}
In this example, the code sets the value stored at location 100 in the computer system to 0. It then starts to poll the address until it changes to 255.

An optimizing compiler will assume that no other code will change the value stored in location 100 and so it will remain equal to 0. The compiler will then replace the while loop with something similar to this: -

void foo(void)
{
int *addr;
addr = 100;

*addr = 0;

while (1) /* 1 here means TRUE */
;
}
and the program will loop forever.

However, the address might represent a location that can be changed by other elements of the computer system. For example, it could be a hardware register of a device connected to the CPU. The value stored there could change at any time. The above code would never detect the change.

To prevent the compiler from modifying code in this way, the volatile keyword is used in the following manner: -

void foo(void)
{
volatile int *addr;
addr = 100;

*addr = 0;

while (*addr != 255)
;
}

http://en.wikipedia.org/wiki/Volatile_variable
 reply or leave comment
Janya
Education: University
Degree: B.E
Job: Software Professional
Homepage: www.fx-mails.com/pag..
country code: United States
0 dunos vote up vote down MEESALU date added 31 Dec 1969 send private message to MEESALU
A volatile variable is not allowed to have a local copy of a variable that is different from the value currently held in "main" memory. Volatile modifier requests the JVM to always access the shared copy of the variable so the its most current value is always read.
http://www.vaathsalya.com
 reply or leave comment
MEESALU
Education: University
Degree: MCA
Job: Internet Researcher
Homepage: www.dunome.com..
country code: India

you must register or login
Write comment to this article

the article is What is volatile variable

your relevant comment

see these articles as well:
What is volatile variable

or any of these recently updated articles:
wats new
photoupload.php
whats the best ps2 games out
editors.php
thrisha bathroom sceen

random article:
which is better paypal or egold. does paypal take fees when money is deposited in it.

IMC International, Inc.