This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug ports/11291] potential deadlock in sem_*wait and sem_post for MIPS architectures
- From: "mischa dot jonker at viragelogic dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 18 Feb 2010 12:18:39 -0000
- Subject: [Bug ports/11291] potential deadlock in sem_*wait and sem_post for MIPS architectures
- References: <20100217150652.11291.mischa.jonker@viragelogic.com>
- Reply-to: sourceware-bugzilla at sourceware dot org
------- Additional Comments From mischa dot jonker at viragelogic dot com 2010-02-18 12:18 -------
I understand that adding 'volatile' does not change anything to the behaviour of the macro, and that the atomic
instructions take care of other threads _while inside the atomic_compare_and_exchange_bool_acq macro_. The problem
is, that it doesn't take care of concurrency in the instructions before that.
without volatile the compiler optimizes the code to:
cur = isem->value;
if (isem->value == SEM_VALUE_MAX)
{
__set_errno (EOVERFLOW);
return -1;
}
// if we get a context switch here, and someone else increases isem->value,
// we get a deadlock, because cur contains isem->value+1, and
// atomic_compare_and_exchange_bool_acq can never succeed.
do
{
}
while (atomic_compare_and_exchange_bool_acq (&isem->value, cur + 1, cur));
So, while it doesn't alter the behaviour of atomic_compare_and_exchange_bool_acq, it does put the 'cur = isem->value'
statement inside the while loop. However, changing the patch as proposed does this as well (although for different
reasons: now the compiler is aware that the macro itself (instead of other threads) can change isem->value).
--
http://sourceware.org/bugzilla/show_bug.cgi?id=11291
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.