Talk:Volatile (keyword)

From OSDev Wiki
Jump to: navigation, search

Unless we are planning to document the whole of the C language this really is over the top. There is nothing special to this keyword that makes it more useful than others in OS Development... and just because you found one code listing where you think volatile was neccesary does not mean you should be setting of on a mission to teach the world about volatile. -- Tyler 16:58, 9 May 2007 (CDT)

Agreed, but I do think it has some worth. What about creating a Programming Section for articles like this? --Alboin
Reading the logs, it was more than just one code snippet. Although I think that mentioning it is a good thing, dedicating an entire page to it is over the top. Mentioning the issue on the C and C++ pages should IMO suffice.
The Linux kernel documentation devotes an entire text file to volatile. See [1]. Linus generally considers declaring data as 'volatile' to be a bad thing, particularly for shared data. IMO the arguments made in the document are sound... perhaps its worth talking about them on this page?
To be honest, I don't consider the Linux kernel maintainers to be the last instance in good programming. I also don't like blanket statements like "volatile considered harmful" (erm... then again, I based the Makefile tutorial on a paper "recursive make considered harmful", so that's a bit of a double standard there... :-D ). There are indeed some points made in the text that should be massaged into this article, but I'd also note that it refers to the Linux kernel sources, where support code for mutexes, memory I/O accessors etc. is already in place. -- Solar 07:57, 12 January 2009 (UTC)
The bottom line of that document is not the blanket "don't use volatile" but it rather reads "Don't use volatile because too many of you are too stupid to apply it correctly". And it is that underlying reason that should IMO be addressed. That partly includes the examples of when and when not, but primarily about what volatile itself is about so that people can make their own educated decisions instead of randomly being told that it is bad. - Combuster 11:23, 12 January 2009 (UTC)

Whether you like it or not, the point of this discussion is teaching about what this statement does and when it may be neccessary. I wouldn't be surprised if 95% of all hobby OS's work fine as long as they are compiled without optimizations, but as soon as they try to compile with e.g. -O3 they wonder why nothing works anymore. There's instances and uses where volatile definitely is neccessary (especially I/O related code), and also highly optimized synchronization algorithms typically use them as well. Just because Linux is trying to avoid it doesn't mean it's incorrect or wrong. It is a very powerful keyword if the programmer knows when and how to use it properly. My article intends to provide the basic education. I personally do not think the Linux kernel is the best example of good source code, unless you're trying to write a POSIX compliant operating system. I agree with some points of that article against the use of volatile, but like I said there's many occasions where it definitely is important. And yes, "volatile" does not mean a write/read operation becomes atomic!

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox