question on locking of pthread structures
Stanley Gambarin
stanley@apogee.com
Tue Jun 7 17:32:00 GMT 2005
Hello,
i've ran into this using large application. I was able to reproduce
the problem using a small testcase (attached). It occurs (for me) on
my linux (single-processor) laptop, running vanilla 2.6.11.11
kernel compiled with SMP (i'm not sure whether it matters or not).
Machine is running gentoo, using glibc 2.3.5, compiled with gcc 3.3.4
This problem is reproducible for me on both LinuxThreads and NPTL.
% gcc prio.c -o prio.x -lpthread
% su root # required for running SCHED_RR
% ./prio.x # your output may vary
creating thread 1
thread 1 - start
creating thread 2
thread 2 - start
creating thread 3
thread 3 - start
thread 3 - checking for priority of t1
thread 3 - bumping prio of t1 from 1 to 11
thread 3 - checking for priority of t1
thread 3 - checking for priority of t1
thread 3 - checking for priority of t1
thread 3 - checking for priority of t1
thread 3 - checking for priority of t1
thread 1 - lowering priority after being bumped by t3
thread 3 - checking for priority of t1 <=== t3 hangs
thread 2 - continue busy loop
thread 2 - continue busy loop
thread 2 - continue busy loop
thread 2 - continue busy loop
thread 2 - continue busy loop
thread 2 - done
thread 3 - bumping prio of t1 from 1 to 11
thread 3 - continue busy loop
thread 3 - done
thread 1 - continue busy loop
thread 1 - done
what's happening (i think) is that t1 got scheduled out (when we
lowered it's priority) while still holding lock for it's internal data
structure. t3 will attempt to access that structure (via
pthread_getschedparams)
and since it can not get a hold of the lock, t2 will run. Running this
test case
on 3 other RTOSs did not cause t3 to be scheduled out. The questions are:
a) is this a bug or a feature of pthread implementation on linux
b) can i somehow tell pthread library to not schedule out threads until
internal mutexes have been freed (if my assumption above is correct)
c) is there an easy configuration fix for the above problem (i don't have
a restriction on compiler/kernel/etc).
Any help in getting this problem resolved would be highly appreciated.
Please CC: me on the replies, since I am not part of the mailing list.
Thanks,
-- stanley
-------------- next part --------------
A non-text attachment was scrubbed...
Name: prio.c
Type: text/x-csrc
Size: 4188 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20050607/1e62ae56/attachment.bin>
More information about the Libc-alpha
mailing list