Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Volatile (http://www.go4expert.com/forums/volatile-t383/)

arangasoft 15Jul2005 17:24

hai every one,

I have some doubt about the keyword 'volatile'.can any one tell me
about volatile and what is the use of that? and where it is required?.
how we can use that in efficient manner.I want to know completely
about the keyword "VOLATILE".

please reply me soon.


shabbir 15Jul2005 18:30

Re: Volatile
Hello arangasoft

Seen you here after quite sometime and something about the volatile keyword.

If you using a multithreaded program and your one thread is something like

if (myVar ==  NULL)
  if (myVar == NULL)

Now consider the situation that SomeFunction is a very long process and in some cases the some other thread can edit the value of myVar then for second condition testing you are in trouble as compiler in process of optimization may not test the condition again and may skip it as always true but if you declare the myVar as volatile then it signals the compiler that its just not the one thread that operates on the variable and so it will not cache the second condition.


volatile MyClass* myVar;
Thanks and hope it helps
Shabbir Bhimani

All times are GMT +5.5. The time now is 22:54.