Re: Is gcc thread-unsafe?

Andi Kleen
2007-10-26T20:39:21Z

Alan Cox <alan@lxorguk.ukuu.org.uk> writes:
>
> You can stop the compiler but not the CPU - and some processors will
> certainly speculatively load across conditionals, reorder writes etc

The difference is that the CPU knows how to cancel most[1] side effects
of these speculative accesses (e.g. by not issuing exceptions[2] etc.).

The compiler doesn't normally (except on some architectures with special support like IA64;
but I'm not sure gcc supports it there)

[1] In some it can't and we've had problems with that in the past. e.g. in
a few cases speculative reads can be a problem. But we generally fix or
workaround those cases in the code.
[2] Modulo hardware bugs -- see the hall of shame in x86_64 fault.c

-Andi