mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Panagiotis Issaris <panagiotis.issaris@mech.kuleuven.ac.be>
To: linux-kernel@vger.kernel.org
Subject: thread creation problem
Date: Thu, 04 Mar 2004 02:19:09 +0100	[thread overview]
Message-ID: <4046840D.8020200@mech.kuleuven.ac.be> (raw)

[-- Attachment #1: Type: text/plain, Size: 1311 bytes --]

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.

[-- Attachment #2: thr_prio_basic.c --]
[-- Type: text/x-c, Size: 1246 bytes --]

#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 );
}

                 reply	other threads:[~2004-03-04  1:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4046840D.8020200@mech.kuleuven.ac.be \
    --to=panagiotis.issaris@mech.kuleuven.ac.be \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®