The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Get real value from real-time systems iBot Complex Event Processing RSS News 0 01-13-2008 10:10 PM
capturing real time wisher115 UNIX for Dummies Questions & Answers 2 09-22-2006 06:26 PM
EPOCH to real time? TheEngineer UNIX for Advanced & Expert Users 5 07-18-2006 05:30 AM
log users real time chanfle UNIX for Dummies Questions & Answers 3 03-22-2006 01:31 PM
multiplex programming in real-time OS. bsderss UNIX for Advanced & Expert Users 0 08-10-2005 01:24 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-06-2007
Registered User
 

Join Date: Mar 2007
Posts: 3
Schedule Real time threads

I want to set the priority and the scheduler as SCHED_FIFO for two threads . I want to see that the thread with high priority will run forever .
A simple code is given below . But both the threads are being scheduled . Why this is happening ?
I am executing the code as root.
I expect to see only the string P1 since the function doit1 is being executed by the thread with priority 35. But the string P2 is also being printed whose thread priority is 32.
#include<stdio.h>
#include<pthread.h>
#include<sys/types.h>


void *doit1(void *);
void *doit2(void *);
pthread_attr_t tattr1;
pthread_attr_t tattr2;
struct sched_param param1;
int main()
{
int i,a;
pthread_t th1,th2;
pthread_attr_init(&tattr1);
pthread_attr_init(&tattr2);
pthread_attr_setschedpolicy(&tattr1 , SCHED_FIFO);
pthread_attr_setschedpolicy(&tattr2 , SCHED_FIFO);
param1.sched_priority=35;
pthread_attr_setschedparam(&tattr1 , &param1);
param1.sched_priority=32;
pthread_attr_setschedparam(&tattr2 , &param1);
pthread_create(&th1,&tattr1,doit1,NULL);
pthread_create(&th2,&tattr2,doit2,NULL);
pthread_join(th1,NULL);
pthread_join(th2,NULL);
}
void * doit1(void *ptr)
{
while (1)
write(1,"P1",2);
return NULL;
}
void * doit2(void *ptr)
{

while (1)
write(1,"P2", 2);
return NULL;
} 54,1 68%
Reply With Quote
Google UNIX.COM
Forum Sponsor
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:02 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0