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-28 at 22:41 +0100, Richard Guenther wrote:
> > OK .. hmm .. well this is the idea, but a more formal proof
> > would be cool.
> Doesn't work:
Of course it works.
> you cannot do such analysis without seeing the whole program.
There's no need. A mutex is assumed at each function call.
That is, registers are dumped to variables at each
* function entry
* function return
This means you cannot merely, say, push caller save
registers when calling a function, and you cannot leave
values in callee save registers, if the variable aliased
In your example:
void foo(bool locked)
I see no problem, a is in memory, you can safely do
if(!locked) goto end;
r0 <- a; r0++; a <- r0;
Since 'a' here is sharable, the function can assume it
is not aliased in a register, load and increment it
and store it back.
It doesn't matter then, whether there is a mutex or not.
In fact, it doesn't matter if locked is true or false.
I also can't see anything at all is lost here.
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net