>>>>> "skaller" == skaller  <[EMAIL PROTECTED]> writes:

skaller> Since 'a' here is sharable, the function can assume it is not
skaller> aliased in a register, load and increment it and store it
skaller> back.

skaller> It doesn't matter then, whether there is a mutex or not.  In
skaller> fact, it doesn't matter if locked is true or false.

skaller> I also can't see anything at all is lost here.

Back to the beginning of this thread. The problem is that when locked
is false, the compiler writes (the previous value) to it anyway.

Look at the generated code for this example with the current
compiler. It is compiled as if it had been written as:

        int a;
        void foo(bool locked)
        {
          a -= locked ? -1 : 0;
        }

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.

  Sam
-- 
Samuel Tardieu -- [EMAIL PROTECTED] -- http://www.rfc1149.net/

Reply via email to