lkml.org 
[lkml]   [2004]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectthread creation problem
Hi,

Creating a thread and afterwards changing the priority and policy does
work. But setting the priority and policy when creating a thread doesn't
seem to work any more on 2.6.x/NPTL systems.

After invoking the following:
pthread_attr_init
pthread_attr_setschedpolicy FIFO
pthread_attr_setschedparam 99
pthread_create

The output of pthread_getschedparam within this thread seemed strange to me:

./thr_prio_basic
max priority 99
policy: 0 priority: 0
thread succesfully created

LD_ASSUME_KERNEL=2.4.1 ./thr_prio_basic
max priority 99
policy: 1 priority: 99
thread succesfully created

Is it because of stricter POSIX compliance of NPTL?

Using ltrace and strace didn't really make it clear to me what is going
wrong here.
In the LinuxThread case, I could clearly see the cloning happening and
afterwards the calls to "sched_setscheduler". In the NPTL case, there is
just a call to clone with more params. No calls to change scheduler
params. Does one of the params contain the scheduler options? If not,
how is the kernel supposed to get that information?

I really don't understand why this is happing, any explanation is
greatly appreciated.

With friendly regards,
Takis

PS: I wasn't sure if I should ask this on the glibc mailinglist or this
mailinglist. My apologies if this is off-topic.
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void* foo( void*p )
{
int policy;
struct sched_param param;
if ( pthread_getschedparam( pthread_self(), &policy, &param ) == 0 )
printf( "policy: %d priority: %d\n", policy, param.sched_priority );
}

int main()
{
pthread_t p;
struct sched_param param;
pthread_attr_t attr;
memset( &param, 0, sizeof( param ) );
param.sched_priority = sched_get_priority_max( SCHED_FIFO );
#if 0
if ( sched_setscheduler( 0, SCHED_FIFO, &param ) == 0 )
printf( "succesfully selected FIFO scheduler\n" );
#endif
printf( "max priority %d\n", param.sched_priority );
if ( pthread_attr_init( &attr ) )
printf( "problem attr init\n" );
if ( pthread_attr_setschedpolicy( &attr, SCHED_FIFO ) )
printf( "problem setschedpolicy\n" );
pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM );
if ( pthread_attr_setschedparam( &attr, &param ) )
printf( "problem setschedparam\n" );
if ( pthread_create( &p, &attr, foo, 0 ) == 0 )
printf( "thread succesfully created\n" );
else
printf( "problem creating thread\n" );
pthread_attr_destroy( &attr );
usleep( 1000000UL );
}
\
 
 \ /
  Last update: 2005-03-22 14:01    [W:0.032 / U:0.336 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site