Interesting...
I've disagreed with many parts of his essays in the past.
Mark Salsbery [MVP] wrote:
http://www.flounder.com/badprogram.htm#beginthread
Very interesting read, but I think the author has it backward what a
certain
compiler guarantees 'volatile' to do[1] and what the C or C++ standards
guarantee. Claiming that declaring even just a flag volatile was enough to
work in a multithreaded environment is definitely wrong, in the sense that
it relies on an implementation detail of a certain compiler (or maybe a
requirement of the win32 API), but that's the case with all multithreaded
programming anyway.
Further, the claim that accesses to an object guarded by a
CRITICAL_SECTION
are unsafe if the object itself is not 'volatile' is plainly wrong. If
this
was true it would mean that you couldn't use e.g. a CString safely,
because
the volatile doesn't e.g. affect the internal types of that object.
Uli
[1] I'm reading the "Using PeekMessage anywhere" paragraph, particularly
referring to the phrase
"The BOOL variable access is carefully synchronized, which is
unnecessary, and it is not declared volatile, which is necessary."