This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Optimization of conditional access to globals: thread-unsafe?

On 22 October 2007 12:27, Tomash Brechko wrote:

> On Mon, Oct 22, 2007 at 12:19:40 +0100, Dave Korn wrote:
>>   *What* mutex are you referring to?  There is no mutex in that code.
> I was talking about the code in the comment#7.  For the code in the
> comment#1, the piece is simply incomplete.  For it, mutex should be
> used if x < 99, not clear if x >= 99.

  Gotcha.  Well, the rule still is: if you want an exact one-to-one
relationship between assignments in your program and externally-visible memory
accesses, use volatile.  C is not a glorified assembler, it is an idealised
virtual machine implemented on the hardware of a real underlying host, and you
can't make assumptions about internal implementation details of that virtual
machine or the relationship between it and the real machine which is hosting
the code.  The optimisation the compiler is making here is a big win in normal
code, you wouldn't want to disable it unless absolutely necessary; to be
precise, you wouldn't want to automatically disable it for every loop and
variable in a program that used -fopenmp just because /some/ of the variables
in that program couldn't be safely accessed that way.

Can't think of a witty .sigline today....

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]