This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Possible pthread bug
- From: Andrew Walrond <andrew at walrond dot org>
- To: libc-alpha at sources dot redhat dot com
- Date: 17 Aug 2002 14:34:26 +0100
- Subject: Possible pthread bug
If I create a thread with pthread_create, and then immediately call
pthread_setschedparam to get a realtime thread, the fn returns 0
(success) but the thread doesn't get the higher priority. Interesting
the internally created pthread manager thread *does* get the higher
priority.
ps output
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY CMD
100 R 0 1675 1621 99 85 0 - 2404 - pts/1 threads
040 S 0 1676 1675 0 57 0 - 2404 schedu pts/1 threads
040 S 0 1677 1676 0 75 0 - 2404 schedu pts/1 threads
If I introduce a delay (with sleep) between creation and setschedparam,
it works fine.
ps output with sleep
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY CMD
100 R 0 1664 1621 85 85 0 - 2404 - pts/1 threads
040 S 0 1665 1664 0 57 0 - 2404 schedu pts/1 threads
040 S 0 1666 1665 0 58 0 - 2404 schedu pts/1 threads
Is this behavior correct?
I'm using glibc 2.2.5 with gcc 3.2 on RH7.3 (i386)
Simple example follows (gcc -o threads -lpthread threads.cpp)
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
void* ThreadFn(void* context)
{
while (true) sleep(1);
}
int main(int argc,char* argv[])
{
pthread_t tid;
int res = pthread_create(&tid,0,ThreadFn,0);
//sleep(1);
sched_param sp;
sp.sched_priority=1;
res = pthread_setschedparam(tid,SCHED_RR,&sp);
printf("pthread_setschedparam returned %d\n",res);
while (true) sleep(0);
return 0;
}