Re: Thread behaviour using pthread
- From: "Igor" <igor_k70@xxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 15:32:01 -0500
Hi Dave,
Here is a small example of how I was setting thread attributes:
main (int argc, char **argv)
{
pthread_attr_t attr;
struct sched_param sched_prio;
pthread_t PthreadId;
int Pri, Policy, ThreadNum, scope = -1;
int ErrorCode;
pid_t Pid;
struct sched_param SchedParam, GetSchedParam;
Pid = getpid();
printf("\n Main process pid = %d", Pid);
pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED);
// Setting scheduling policy and priority
sched_prio.sched_priority = 10;
// set the task priority
pthread_attr_setschedparam( &attr, &sched_prio);
// set thread creation state
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
// set thread policy
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
pthread_attr_getschedpolicy (&attr, &Policy);
pthread_attr_getscope (&attr, &scope);
if (Policy == SCHED_FIFO) {
printf ("\nPolicy = FIFO\n");
} else if (Policy == SCHED_RR) {
printf ("\nPolicy = RR\n");
} else if (Policy == SCHED_OTHER) {
printf ("\nPolicy = OTHER\n");
}
if (scope == PTHREAD_SCOPE_SYSTEM) {
printf("\n PTHREAD_SCOPE_SYSTEM\n");
} else if ( scope == PTHREAD_SCOPE_PROCESS ) {
printf ("\n PTHREAD_SCOPE_PROCESS\n");
}
// Start task
ThreadNum = 1;
// Initialize attributes for the new thread
pthread_attr_init(&attr);
// Start task
ThreadNum = 1;
ErrorCode = pthread_create(&PthreadId, &attr,
ThreadEntry1,
&ThreadNum );
"David Schwartz" <davids@xxxxxxxxxxxxx> wrote in message
news:e020mh$ipb$1@xxxxxxxxxxxxxxxxxxxxx
a
"Igor" <igor_k70@xxxxxxxxxxx> wrote in message
news:e01713$dnh$1@xxxxxxxxxxxxxxxxxxxxxxxxx
I have tried using pthread library on Linux (2.6 kernel) and found that
setting parameters in the attr structure
do not seem to change anything in the thread behaviour - changing sched
policy (RR, FIFO) or RT priority. So, it seems that any changes to attr
structure for a thread are transparent. The only way I could change the
behaviour is by using process level calls like sched_setscheduler etc.on
thread.
Is there anything I am missing?
Post minimal example code, you may be doing it wrong. It's not
particularly difficult, but there are a few gotchas.
DS
.
- References:
- Thread behaviour using pthread
- From: Igor
- Re: Thread behaviour using pthread
- From: David Schwartz
- Thread behaviour using pthread
- Prev by Date: Re: Thread behaviour using pthread
- Next by Date: Re: Thread behaviour using pthread
- Previous by thread: Re: Thread behaviour using pthread
- Next by thread: P2P VOIP library ?
- Index(es):
Relevant Pages
|