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

Possible bug in NPTL in handling pthread_attr



Hi,

I just installed fedora core 1 and all the updates and am running the kernel 2.4.22-1.2149.nptl.

In order to compare context switch times in Linuxthreads vs NPTL, 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 that the policy and priority are both 0.

_____________________________________________________________________________________

#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





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