Re: Is gcc thread-unsafe?

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Andrew Haley
Date: Friday, October 26, 2007 - 4:59 am

[ I had to resend this message.  Sorry if you received two copies. ]

Nick Piggin writes:
 > Can you retain cc list, please?
 > 
 > On Friday 26 October 2007 07:42, David Schwartz wrote:

 > > 	I asked a collection of knowledgeable people I know about the
 > > issue. The consensus is that the optimization is not permitted in
 > > POSIX code but that it is permitted in pure C code. The basic
 > > argument goes like this:
 > >
 > > 	To make POSIX-compliant code even possible, surely
 > > optimizations that add writes to variables must be
 > > prohibited. That is -- if POSIX prohibits writing to a variable
 > > in certain cases only the programmer can detect, then a
 > > POSIX-compliant compiler cannot write to a variable except where
 > > explicitly told to do so. Any optimization that *adds* a write to
 > > a variable that would not otherwise occur *must* be prohibited.

I don't think that POSIX is quite as explicit as that.  See
http://www.hpl.hp.com/techreports/2004/HPL-2004-209.pdf

 > > 	Otherwise, it is literally impossible to comply with the POSIX
 > > requirement that concurrent modifications and reads to shared
 > > variables take place while holding a mutex.
 > 
 > Now all you have to do is tell this to the gcc developers ;)

We're listening, really.  It's unacceptable that gcc should break
code.

However, fixing it is hard.  The best plan is probably to implement
(part of) the proposed standard memory model, and that requires
careful consideration.  We could in theory simply disable this
particular optimization, but that probably isn't a good idea on its
own because other optimizations might well break other code in a
similar way.  We need to have a very close look at the thread-safe
memory model in order to determine where we do things that might
break.

An official standard containing this is still at least two years out.

Andrew.

-- 
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Is gcc thread-unsafe?, Nick Piggin, (Wed Oct 24, 8:24 pm)
Re: Is gcc thread-unsafe?, Arjan van de Ven, (Wed Oct 24, 8:46 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Wed Oct 24, 8:58 pm)
RE: Is gcc thread-unsafe?, David Schwartz, (Wed Oct 24, 9:29 pm)
Re: Is gcc thread-unsafe?, Arjan van de Ven, (Wed Oct 24, 9:35 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Wed Oct 24, 9:47 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 12:15 am)
Re: Is gcc thread-unsafe?, Samuel Tardieu, (Thu Oct 25, 2:44 am)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 2:55 am)
Re: Is gcc thread-unsafe?, linux-os (Dick Johnson), (Thu Oct 25, 4:58 am)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 5:16 am)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 7:55 am)
Re: Is gcc thread-unsafe?, Pekka Enberg, (Thu Oct 25, 8:12 am)
RE: Is gcc thread-unsafe?, David Schwartz, (Thu Oct 25, 2:42 pm)
Re: Is gcc thread-unsafe?, Ismail , (Thu Oct 25, 3:26 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 3:49 pm)
Re: Is gcc thread-unsafe?, Jeff Garzik, (Thu Oct 25, 3:56 pm)
Re: Is gcc thread-unsafe?, Jeff Garzik, (Thu Oct 25, 4:04 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 4:09 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 4:14 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 4:16 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 4:22 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 4:32 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 4:42 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 4:43 pm)
Re: Is gcc thread-unsafe?, Andi Kleen, (Thu Oct 25, 4:55 pm)
Re: Is gcc thread-unsafe?, Nick Piggin, (Thu Oct 25, 4:57 pm)
Re: Is gcc thread-unsafe?, Linus Torvalds, (Thu Oct 25, 4:57 pm)
Re: Is gcc thread-unsafe?, Zachary Amsden, (Thu Oct 25, 6:15 pm)
Re: Is gcc thread-unsafe?, Willy Tarreau, (Thu Oct 25, 9:57 pm)
Re: Is gcc thread-unsafe?, Andrew Haley, (Fri Oct 26, 4:59 am)
Re: Is gcc thread-unsafe?, Andrew Haley, (Fri Oct 26, 4:59 am)
Re: Is gcc thread-unsafe?, Chris Friesen, (Fri Oct 26, 10:39 am)
Re: Is gcc thread-unsafe?, Phillip Susi, (Wed Oct 31, 3:10 pm)