Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Volatile, once more

0 views
Skip to first unread message

Joseph M. Newcomer

unread,
Nov 3, 2004, 1:36:59 PM11/3/04
to
There has been a somewhat acrimonious debate on the meaning and utility of the "volatile"
keyword.

Microsoft just released a new White Paper on multiprocessor synchronization issues.

http://www.microsoft.com/whdc/driver/kernel/MP_issues.mspx

Also, there was an article on the use of volatile in Dr. Dobb's Journal, August 2004,
p.57ff.

Read these and come to your own conclusions.

joe
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Doug Harrison [MVP]

unread,
Nov 3, 2004, 4:21:57 PM11/3/04
to
Joseph M. Newcomer wrote:

>There has been a somewhat acrimonious debate on the meaning and utility of the "volatile"
>keyword.
>
>Microsoft just released a new White Paper on multiprocessor synchronization issues.
>
>http://www.microsoft.com/whdc/driver/kernel/MP_issues.mspx
>
>Also, there was an article on the use of volatile in Dr. Dobb's Journal, August 2004,
>p.57ff.
>
>Read these and come to your own conclusions.
>
> joe

I'd be interested to hear what your conclusions are about this subject, as
you keep bringing it up out of the blue. Having read the relevant parts, I
for one enthusiastically recommend the MS paper you linked to as well as the
DDJ article, which I suppose is this:

C++ and the Perils of Double-Checked Locking: Part II
http://www.ddj.com/documents/s=9220/ddj0408l/

They each reiterate, touch on, and expand upon things I've been telling you
for years in this group in response to the many wrong statements you've made
and the fundamentally flawed "proofs" you've continually attempted
concerning volatile and multithreading programming. Given that your essay on
the subject is still up, I am genuinely curious what your conclusions are.

--
Doug Harrison
Microsoft MVP - Visual C++

Kurt Grittner

unread,
Nov 4, 2004, 9:59:56 AM11/4/04
to
Cool article!

My favorite parts:

If you look at the sample drivers shipped with the Windows DDK, you
will see that volatile appears infrequently. In general, volatile is
of limited use in driver code for the following reasons:

Using volatile prevents optimization only of the volatile variables
themselves. It does not prevent optimizations of nonvolatile variables
relative to volatile variables. For example, a write to a nonvolatile
variable that precedes a read from a volatile variable in the source
code might be moved to execute after the read.

Using volatile does not prevent the reordering of instructions by the
processor hardware.

Using volatile correctly is not enough on a multiprocessor system to
guarantee that all CPUs see memory accesses in the same order.

Windows synchronization mechanisms are more useful in preventing all
these potential problems.

Details of how to implement the volatile keyword are not specified in
the ANSI language standards, but are left to compiler developers.
Therefore, implementations may vary from compiler to compiler. Never
assume that every C compiler or even every version of a single
manufacturer’s C compiler implements volatile in the same way.

- end of snippet

btw, we use volatile alot in the C54x DSP code. It is very helpful on
the TI compiler because of the many fast moving memory mapped
registers and the very deep pipeline which is managed by the compiler.
We hardly ever use it on the Windows platform.

- Kurt

0 new messages