This is the mail archive of the
glibc-bugs@sources.redhat.com
mailing list for the glibc project.
[Bug nptl/145] New: scheduling parameters not set during call to pthread_create
- From: "dahern at avaya dot com" <sourceware-bugzilla at sources dot redhat dot com>
- To: glibc-bugs at sources dot redhat dot com
- Date: 4 May 2004 21:23:56 -0000
- Subject: [Bug nptl/145] New: scheduling parameters not set during call to pthread_create
- Reply-to: sourceware-bugzilla at sources dot redhat dot com
Scheduling parameters -- policy and priority -- are not set when thread is
created even though the parameters are set in the thread attributes.
Example code below. Output (as root) is:
thread id = 0xf701fbb0, policy = SCHED_OTHER, priority = 0
re-setting priority and policy
now schedule data for thread is:
thread id = 0xf701fbb0, policy = SCHED_RR, priority = 25
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <sched.h>
#define HPRIO 25
void show_sched(void)
{
struct sched_param sp;
int policy;
const char *pstr;
if (pthread_getschedparam(pthread_self(), &policy, &sp) != 0) {
perror("pthread_getschedparam failed");
return;
}
switch(policy) {
case SCHED_OTHER:
pstr = "SCHED_OTHER";
break;
case SCHED_FIFO:
pstr = "SCHED_FIFO";
break;
case SCHED_RR:
pstr = "SCHED_RR";
break;
default:
pstr = "unknown";
}
printf("thread id = 0x%lx, policy = %s, priority = %d\n",
pthread_self(), pstr, sp.sched_priority);
return;
}
void set_sched(int policy, int priority)
{
struct sched_param schedp;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = priority;
if (pthread_setschedparam(pthread_self(), policy, &schedp) != 0)
perror("pthread_setschedparam failed");
}
void thread1(void)
{
show_sched();
printf("\nre-setting priority and policy\n");
set_sched(SCHED_RR, HPRIO);
printf("\nnow schedule data for thread is:\n");
show_sched();
return;
}
int main(void)
{
pthread_attr_t attr;
struct sched_param schedp;
pthread_t id1;
int rc;
/*
* Create thread at high priority
*/
if (pthread_attr_init(&attr) != 0) {
perror("pthread_attr_init failed");
return 1;
}
/* set schedule policy */
if (pthread_attr_setschedpolicy(&attr, SCHED_RR) != 0) {
perror("pthread_attr_setschedpolicy failed");
return 1;
}
/* set schedule priority */
schedp.sched_priority = HPRIO;
if (pthread_attr_setschedparam(&attr, &schedp) != 0) {
perror("pthread_attr_setschedparam failed");
return 1;
}
/* create thread */
rc = pthread_create(&id1, &attr, (void *(*)(void *))thread1, 0);
if (rc) {
perror("pthread_create failed");
return(1);
}
pthread_attr_destroy(&attr);
pthread_join(id1, NULL);
return(0);
}
--
Summary: scheduling parameters not set during call to
pthread_create
Product: glibc
Version: 2.3.3
Status: NEW
Severity: normal
Priority: P2
Component: nptl
AssignedTo: drepper at redhat dot com
ReportedBy: dahern at avaya dot com
CC: glibc-bugs at sources dot redhat dot com
http://sources.redhat.com/bugzilla/show_bug.cgi?id=145
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.