Subj : Re: Memory Barriers, Compiler Optimizations, etc. To : comp.programming.threads From : David Schwartz Date : Sat Feb 05 2005 05:26 pm "Scott Meyers" wrote in message news:MPG.1c6e9cce1b4cdb059897c0@news.hevanet.com... > Well, the C++ standard seems pretty clear to me that the sequence of reads > and writes to volatile data separated by sequence points must be preserved > by a conforming compiler. I can't tell from a quick glance whether the > C99 > standard offers the same guarantee. So what is the basis for the "can't > rely on any guarantees" camp? That there are many nonconforming > compilers? > That the guarantee doesn't exist in C? This is a meaningless requirement because it doesn't say *where* the order needs to be preserved. One could argue that an L2 cache violates this requirment and the C standard requires you to disable the L2 cache for volatile accesses. The problem is that the standard simply calls the order of such accesses part of the 'oberservable behavior' of the program with no concept of how or where such a thing is to be observed. > I think we all agree that volatile alone can't solve the problem, because > it affects only compilers, not hardware-based instruction reorderings. It does not affect the compiler. The 'as-if' rule permits the compiler to make any changes that don't affect the observable behavior. Since nobody can agree how this is observable behavior, there is effectively no restriction on compilers either. DS .