Optimization of conditional access to globals: thread-unsafe?
skaller
skaller@users.sourceforge.net
Mon Oct 29 11:24:00 GMT 2007
On Mon, 2007-10-29 at 10:37 +0100, Samuel Tardieu wrote:
> >>>>> "skaller" == skaller <skaller@users.sourceforge.net> writes:
> with (x86):
>
> movl a, %eax
> cmpl $1, 4(%esp)
> sbbl $-1, %eax
> movl %eax, a
>
> There is clearly a race condition if you have multiple threads
> executing this code even if only one thread has "locked" being true.
Ah .. ok I think I finally see. Thanks! The code ensures
well definedness by checking the establishment of the
required invariant and dynamically chosing whether or not
to do the access on that basis .. and the optimisation
above defeats that by lifting the access out of the
conditional.
In the single threaded case the lift works because it
relies on sequential access, which is the only possibility
for a single thread.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
More information about the Gcc
mailing list