This is the mail archive of the
mailing list for the GCC project.
Re: Optimization of conditional access to globals: thread-unsafe?
On Sun, 2007-10-21 at 20:16 +0400, Tomash Brechko wrote:
> But if C99 is thread-neutral, then it's compiler's responsibility to
> ensure the same result as some abstract machine
No. The compiler is responsible for ensuring that things work
if, and only if:
1. your program conforms in required ways
2. you only call functions in the standard library
or functions you define in your program
Therefore, when making calls to ANY external library,
all bets are off UNLESS that library also meets the above
Interfacing the operating system in any way OTHER than
the C standard library functions immediately relieves
the compiler of all responsibility -- and that includes
calls to Posix functions which are not implemented
entirely in Standard C.
Of course, a C compiler may make additional guarantees,
for example, Posix compliance, but then you must check
the Posix standard to see what additional things it
AFAIK, access to a shared variable is sound if serialised
by a mutex. However that isn't a proper description,
there are situations where you can safely read a shared
variable without a lock being held, for example if you know
another thread has not modified it since the last synchronisation.
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net