Bug in NPTL in handling pthread_attr

Abhijeet Bisain abisain at qualcomm.com
Tue Feb 3 01:44:53 UTC 2004


Hi,

	I just installed fedora core 1 and wanted to try out the NPTL library. 
Then I got the latest kernel and all pkg updaed.

	I wrote a small program to create a thread at a certain real time priority 
by setting the schedpolicy and sched_param in the pthread_attr that I pass 
to the pthread_create. In the created thread, i check the sched_param to 
make sure its priority and schedpolicy are set correctly.

	To my surprise, the policy and priority were both set to 0,even though I 
had set them to SCHED_FIFO and 20 respectively.  Has anyone else seen this?

	Can somebody please explain if I am doing something wrong? I used 
LD_ASSUME_KERNEL to switch between linuxthreads and NPTL. Linuxthreads 
seems to pass this test.

Here's the code. This code when compiled prints

_____________________________________________________________________________________

#include <pthread.h>
#include <stdio.h>
#include <sys/time.h>

#define HI_PRI 20

//
// Wrapper function to initialize pthread_attr, set the priority and create 
a thread
//
int taskSpawn( int prio, void *(*start_routine)(void *))
{
	pthread_t spawner_id;
	pthread_attr_t spawner_attr;
	struct sched_param spawner_sched_param;
	if ( pthread_attr_init(&spawner_attr) != 0 )
	{
		perror("attr_init:");
		return -1;
	}
	if(pthread_attr_setschedpolicy( &spawner_attr, SCHED_RR) != 0)
         {
                 perror("setschedpolicy:");
                 return -1;
         }
         if(pthread_attr_getschedparam(&spawner_attr, & 
spawner_sched_param) != 0)
         {
                 perror("getschedparam:");
                 return -1;
         }
	spawner_sched_param.sched_priority = prio;
	if(pthread_attr_setschedparam(&spawner_attr, &spawner_sched_param) != 0)
         {
                 perror("setschedparam ");
                 return -1;
         }
	if (pthread_create(&spawner_id, &spawner_attr, start_routine, NULL) != 0)
         {
                 perror("pthread_create locker");
                 return -1;
         }
	return spawner_id;
}

//
//  This is the thread routine which checks the schedparam for the sched 
policy and priority
//
void * high(void *tmp)
{
	struct sched_param hisched_param;
	int policy;
	if ( pthread_getschedparam(pthread_self(), &policy, &hisched_param) != 0 )
	{
		perror("pthreadschedparamhi:");
		return NULL;
	}
	printf("Thread's priority = %d, policy = %d\n", 
hisched_param.sched_priority, policy);
}

int main()
{
	pthread_t spawner_id;

	spawner_id = taskSpawn(HI_PRI , high);
	if( pthread_join(spawner_id, NULL) != 0 )
	{
		perror("pthreadjoin:");
	}
}

___________________________________________________________________

Thanks,
Abhijeet 





More information about the fedora-list mailing list