From: "yang" <wchyang_hn@sina.com>
To: <linuxppc-embedded@lists.linuxppc.org>
Subject: Can't set the schedual parameter of threads in linux
Date: Thu, 11 Mar 2004 09:06:54 +0800 [thread overview]
Message-ID: <002901c40705$65697ee0$5e1312ac@yang> (raw)
Hello,
I encounter a problem when I transplant application.
There is no effect to the pthread when I call pthread_setschedparam() function in test program, and it's policy and priority are stilll zero, not what I expected, after call pthread_getschedparam(). The codes is as the follow:
#include <sched.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <linux/ipc.h>
#include <linux/msg.h>
#include <errno.h>
#include <stddef.h>
#include <string.h>
void * func()
{
while (1);
return;
}
int main()
{
pthread_attr_t tattr;
pthread_t tid;
int policy;
int ret;
int newprio = 20;
struct sched_param param;
ret = pthread_attr_init (&tattr);
if (ret != 0)
{
printf("Error in init: %s\n", strerror(errno));
}
ret = pthread_attr_getschedparam (&tattr, ¶m);
if (ret != 0)
{
printf("Error in get after init: %s\n", strerror(errno));
}
ret = pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
if (ret != 0)
{
printf("Error in setdea: %s\n", strerror(errno));
}
ret = pthread_attr_setschedpolicy(&tattr, SCHED_RR);
if (ret != 0)
{
printf("Error in setpolicy: %s\n", strerror(errno));
}
param.sched_priority = newprio;
ret = pthread_attr_setschedparam (&tattr, ¶m);
if (ret != 0)
{
printf("Error in set: %s\n", strerror(errno));
}
ret = pthread_create (&tid, &tattr, (int*) func, NULL);
if (ret != 0)
{
printf("Error in create: %s\n", strerror(errno));
}
param.sched_priority = -1;
ret = pthread_getschedparam (tid, &policy, ¶m);
if (ret != 0)
{
printf("Error in get after create: %d %s\n", ret, strerror(errno));
}
printf("policy: %d\tpriority: %d\n", policy, param.sched_priority);
return 0;
}
The output is :
policy: 0 priority: 0
Would you like to tell me how to set the policy and priority to pthreads in Red Hat.? Thank you very much!
Best regards,
yang
** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/
next reply other threads:[~2004-03-11 1:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-11 1:06 yang [this message]
2004-03-11 11:56 ` Can't set the schedual parameter of threads in linux Jaap-Jan Boor
[not found] ` <001601c4076a$465d6470$5e1312ac@yang>
2004-03-11 15:04 ` Jaap-Jan Boor
2004-03-11 15:10 ` Mark Hatle
-- strict thread matches above, loose matches on Subject: below --
2004-03-11 15:22 Jean-Denis Boyer
2004-03-11 15:37 ` Jaap-Jan Boor
2004-03-11 19:39 erik.teose
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='002901c40705$65697ee0$5e1312ac@yang' \
--to=wchyang_hn@sina.com \
--cc=linuxppc-embedded@lists.linuxppc.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.