Thread starvation with mutex
Luke Elliott <[email protected]> Fri, 06 Feb 2004 16:07:48 -0600
| Newsgroups | gmane.comp.lib.phil |
|---|---|
| Message-ID | <[email protected]> |
I have seen some behaviour with mutexes which I think is unusual and
probably not expected. I can provide some code for this if required, but
here is a summary of what I was doing:
mutex = non pshared, recursive mutex
Thread 1
--------
while (true)
{
acquire mutex
suspend 2 seconds
release mutex
}
Thread 2
--------
while (true)
{
acquire mutex
release mutex
}
The behaviour I've seen is Thread 2 never manages to acquire the mutex.
Initially I thought this was due to the requeue issue
(https://listman.redhat.com/archives/phil-list/2003-November/msg00032.html)
as I was using a pshared mutex, but I see the same behaviour with a
private mutex.
I don't know what the standard has to say in this area, but is this
expected? Surely there should be some FIFO queueing of waiters here?
I've run the same test on FreeBSD 5.2 and see the behaviour I expect -
Thread 2 is allowed to run every 2 seconds. I could also try this on
Solaris but haven't yet. (A similar test on Win32 has thread 2 waking up.)
This is on Fedora Core 1, with 2.6.2 kernel and the latest glibc update.
Any insight would be appreciated.
Regards
Luke Elliott.