pthread_{mutex,cond} & fifo/starvation/scheduling policy

Bernard van Gastel bvgastel at bitpowder.com
Tue Jan 19 11:01:50 UTC 2010


Hi everyone,

I'm curious to the exact scheduling policy of POSIX threads in relation to mutexes and conditions. If there are two threads (a & b), both with the following code:

while (1) {
	pthread_mutex_lock(mutex);
	...
	pthread_mutex_unlock(mutex);
}

What is the scheduling policy of the different thread libraries? Are both threads getting an equal amount of time? Are there no starvation issues (are they executed in alternating turns)? (a test program of mine indicates that libpthread and libthr both have starvation issues, in contrary to Mac OS X 10.6)

Also, I'm interested in the scheduling behaviour in combination with pthread_cond. Get a signalled thread priority to relock the mutex it is waiting on, or is the relock operation just a normal lock operation and is handled as such? (so different kind of starvation issues can occur in the latter case)

I have googled extensively and browsed the libthr sources, but can't find the specs that I'm looking for. Any help will appreciated.

With regards,
  Bernard van Gastel


More information about the freebsd-hackers mailing list