-
April 20th, 2010, 11:08 PM
#1
The "volatile trick"
A while back I read this column:
http://www.drdobbs.com/cpp/184403766
which proposes "stealing" the volatile keyword to aid in establishing thread safety. This usage has nothing to do with the actual meaning of volatile; it just exploits the fact that it's part of the C++ type system.
Now, I came to the conclusion quickly that this was a bad idea. Neat, and I'd go with it in a second if there were a purpose-built keyword, but borrowing the volatile keyword for an unrelated use just seems to be asking for trouble; especially given the confusion which sometimes arises when Java programmers think that calling something volatile makes it thread safe (when it does nothing of the kind in C++).
I would like the opinions of the experts on this matter, however, because it's interesting enough as a concept.
-
April 20th, 2010, 11:52 PM
#2
Re: The "volatile trick"
FWIW, an old (and long) thread, with Mr. Alexandrescu and other industry experts - http://groups.google.com/group/comp....878c22d7775997
All other issues aside, my biggest gripe is the potential for confusion when putting the two together (volatile + multi-threading). Of course, MS giving multi-threaded semantics to volatile in MSVC v14/2005 didn't help the situation at all.
gg
-
April 21st, 2010, 12:22 PM
#3
Re: The "volatile trick"
I don't consider myself any kind of expert in this area, but I would recommend a different keyword. For something that has been established for so long, additional usage will be confusing. And, if there are any (unforeseen) side effects, recompilation of codes with the original use of "volatile" could break applications that have worked up to that point.
Why not something like "threadsafe" as the new keyword? It's only got 2 more letters than "volatile." :-)
Clay Breshears
Intel Innovative Software Education
"There are no evil threads; just threads programmed for evil."
-
April 21st, 2010, 07:33 PM
#4
Re: The "volatile trick"
^That'd be nice, but I think we have to stick with what the language provides now and in 1x.
 Originally Posted by Codeplug
Of course, MS giving multi-threaded semantics to volatile in MSVC v14/2005 didn't help the situation at all.
Ack, really? Don't spread it around. Maybe no one will notice.....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|