Schedule Real time threads


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Schedule Real time threads
# 1  
Old 09-07-2007
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%
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Schedule task on some date and time.

Hi ! all I am interested to know how to schedule some task, say delete some directory which needs root privileges, please someone suggest me other than crontab Here is a scenario schedule date is 25-09-2013 time 10:00 AM to 11:00 AM delete directory log in following path ... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

2. Shell Programming and Scripting

Converting real time to epoch time

# date +%s -d "Mon Feb 11 02:26:04" 1360567564 # perl -e 'print scalar localtime(1360567564), "\n";' Mon Feb 11 02:26:04 2013 the epoch conversion is working fine. but one of my application needs 13 digit epoch time as input 1359453135154 rather than 10 digit epoch time 1360567564... (3 Replies)
Discussion started by: vivek d r
3 Replies

3. Shell Programming and Scripting

Shell script to convert epoch time to real time

Dear experts, I have an epoch time input file such as : - 1302451209564 1302483698948 1302485231072 1302490805383 1302519244700 1302492787481 1302505299145 1302506557022 1302532112140 1302501033105 1302511536485 1302512669550 I need the epoch time above to be converted into real... (4 Replies)
Discussion started by: aismann
4 Replies

4. Programming

problem with real-time

hello every1, i'm very hope so anyone here have experience with lib rt like aio linux based. In first I've a problem with receiving data from aio_buf, i.e. I have received it, but if the next data size less then pervious I've got a noise from a socket. I've tried to fix it by different ways, but... (0 Replies)
Discussion started by: quant
0 Replies

5. Solaris

Real time problems

Hi friends, I am new to solaris and looking for a job, when ever i attend interview i get most of the questions on real time problems, every one sak me the same questions what are the problems you face daily.. and what are the types? i know few like, disk extension,swap memory increasing,... (2 Replies)
Discussion started by: kurva
2 Replies

6. UNIX for Advanced & Expert Users

EPOCH to real time?

hi all :confused: i am wondering if there is a way to convert from EPOCH time to the standard tim, may be using a script or some thing else??????? thanks............................ (5 Replies)
Discussion started by: TheEngineer
5 Replies
Login or Register to Ask a Question