3 ms·
Excellent LWN piece, as usual. I just want to point out that there ARE cases where you MUST use volatile in userland. For instance, double-checked locking (see
by ComputerGuru 16y ago
Excellent LWN piece, as usual.
I just want to point out that there ARE cases where you MUST use volatile in userland. For instance, double-checked locking (see this Scott Meyers essay on DDJ for info: http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf) is only guaranteed to work on the MSCV compiler as of the 2005 release (and others at different versions) with volatile bools (though the same caveats mentioned on LWN will apply): http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Microsoft_Visual_C.2B.2B http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in...
- dschobel 16y agoThe particularly pernicious thing about this flaw in the most common implementation of double checked locking is that it seems like such a simple optimization to one of the most common programming patterns, the singleton. The singleton is something which the majority of programmers understand vs realizing that the runtime can optimize reads and writes to memory by doing things which make sense in the context of one thread but break in multiple is something I'd only expect the top 10% (and that may be generous) of programmers to understand. So having the complex part be an intuitive (but wrong) optimization to the easy bit is just a deadly combination.