pthread_attr_setschedpolicy(), pthread_attr_setschedparam(), pthread_attr_setinheritsched() not working with NPTL

Takashi Oe <[email protected]>
Newsgroups gmane.comp.lib.phil
Message-ID <Pine.A41.3.96LJ1.1b7.1030728070605.56882B-100000@unlserve.unl.edu>
Hi,

The following code produces the output "priority = 0, policy = 0", while
it seems the output of "priority = 10, policy = 1" be more appropriate:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>

static void *thread(void *unused)
{
        struct sched_param p;
        int policy;

        pthread_getschedparam(pthread_self(), &policy, &p);

        fprintf(stderr, "priority = %d, policy = %d\n", p.sched_priority,
		policy);

        pthread_exit("DONE");
}

int main(void)
{
        pthread_attr_t attr;
        struct sched_param p;
        pthread_t tid;

        pthread_attr_init(&attr);
        pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
        p.sched_priority = 10;
        pthread_attr_setschedparam(&attr, &p);
        pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);

        pthread_create(&tid, &attr, thread, NULL);
        pthread_join(tid, NULL);

        return 0;
}

After some searching, I found that changing
nptl/pthread_create.c::__pthread_create_2_1()'s following line:

  if (0 && attr != NULL)

to

  if (attr != NULL)

makes the sample code work as expected.

It seems setting the scheduling portion of user attr were intentionally
disabled in nptl.  Does it still need to be disabled?  Could someone tell
me what the issues are?


Takashi Oe
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.