Newbie question on mutexes

Abhijeet Bisain <[email protected]> Thu, 12 Feb 2004 15:53:25 -0800
Newsgroups gmane.comp.lib.phil
Message-ID <[email protected]>
Hi,

	I am seeing a different behavior between Linuxthreads and NPTL when it 
comes to threads of different priorities waiting on a pthread_mutex. Here's 
what I do in my code:

1. create a pthread_mutex and lock it.
2. create a real time thread with policy SCHED_FIFO and priority 5. This 
thread tries to lock the same mutex and blocks.
3. create a second thread with policy SCHED_FIFO and priority 10. This 
thread tries to lock the same mutex and blocks.
4. then I unlock the mutex and check who got the lock.

When I run this with Linuxthreads, the higher priority thread gets the 
lock. When I use NPTL, the lower priority one gets it.

My test system is Fedora core 1, running 2.4.22-1.2166.nptl kernel on an 
x86 . I am using LD_ASSUME_KERNEL to switch between NPTL and Linuxthreads. 
I set it to 2.4.19 to go to Linuxthreads and unset it to go back to NPTL, 
which is the default. I also make sure the correct library is being used by 
doing an ldd on the program. NPTL devel library is nptl-devel-2.3.2-101.4. 
glibc is glibc-2.3.2-101.4

Can someone please let me know what I am doing wrong. I would have expected 
the higher priority thread to get the mutex, but don't see that behavior in 
NPTL.

Thanks,
Abhijeet