This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Optimization of conditional access to globals: thread-unsafe?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]