What is the keyword volatile used for? What sort of situations should I use volatile when developing a multi-threaded application?

Shashi Bhusan Thakur

Volatile modifiers tells the compiler that the variable can be changed unexpectedly by other part of programme. When you have nore than one thread and you expect any thread can change the variable you should use volatile. This will tell the compiler to check for the master copy of this variable. Mostly used for boolean flags.

[Would the compiler produce incorrect code if it *weren't* marked volatile? What kind of optimizations can it perform if it knows it's volatile? -Alex]

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact