What is the use of Volatile Keyword in C#?

2 views
Skip to first unread message

.NetIndia

unread,
Nov 4, 2005, 4:09:30 AM11/4/05
to dotNetIndia

What is the use of Volatile Keyword in C#?

--
Regards,
.NetIndia Group,
"There is no delight in owning anything unshared."
"A book lying idle on a shelf is wasted ammunition. Like money, books must be kept in constant circulation. Lend and borrow to the maximum -- of both books and money! But especially books, for books represent infinitely more than money. A book is not only a friend, it makes friends for you. When you have possessed a book with mind and spirit, you are enriched. But when you pass it on you are enriched threefold."

Blog:http://dotnetindia.blogspot.com/
Technical Discussion: Techdot...@googlegroups.com
http://groups.google.com/group/TechdotNetIndia
Job Section         : TechdotNet...@googlegroups.com
http://groups.google.com/group/TechdotNetIndia-Jobs

John Rajesh

unread,
Nov 4, 2005, 5:55:02 AM11/4/05
to Techdot...@googlegroups.com
A variable should be declared volatile whenever its value can be changed by something beyond the control of the program in which it appears, such as a concurrently executing thread. Volatile, can appear only once in a declaration with any type specifier; however, they cannot appear after the first comma in a multiple item declaration.
 
Keyword volatile can be placed before or after the data type in the variable definition. For example following declaration are identical:
Volatile T a =3;
T volatile a=3; 
The declaration declares and initializes an objet with type volatile T whose value will be always read from memory

Use of volatile

- An object that is a memory-mapped I/O port
- An object variable that is shared between multiple concurrent processes
- An object that is modified by an interrupt service routine
-
  John Rajesh


Enjoy this Diwali with Y! India Click here

Reply all
Reply to author
Forward
0 new messages