[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

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



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




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]