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
pi_stress(8)						Linux System Administrator's Manual					      pi_stress(8)

NAME
pi_stress - a stress test for POSIX Priority Inheritance mutexes SYNOPSIS
pi_stress [-i|--inversions inversions] [-t|--duration seconds] [-g|--groups groups [-d|--debug] [-v|--verbose] [-s|--signal] [-r|--rr] [-p|--prompt] [-m|--mlockall] [-u|--uniprocessor] pi_stress -h|--help DESCRIPTION
pi_stress is a program used to stress the priority-inheritance code paths for POSIX mutexes, in both the Linux kernel and the C library. It runs as a realtime-priority task and launches inversion machine thread groups. Each inversion group causes a priorty inversion condition that will deadlock if priority inheritance doesn't work. OPTIONS
-i n|--inversions=n Run for n number of inversion conditions. This is the total number of inversions for all inversion groups. Default is -1 for infi- nite. -t n|--duration=n Run the test for n seconds and then terminate. -g n|--groups=n The number of inversion groups to run. Defaults to 10. -d|--debug Run in debug mode; lots of extra prints -v|--verbose Run with verbose messages -s|--signal Terminate on receipt of SIGTERM (Ctrl-C). Default is to terminate on any keypress. -r|--rr Run inversion group threads as SCHED_RR (round-robin). The default is to run the inversion threads as SCHED_FIFO. -p|--prompt Prompt before actually starting the stress test -u|--uniprocessor Run all threads on one processor. The default is to run all inversion group threads on one processor and the admin threads (report- ing thread, keyboard reader, etc.) on a different processor. -m|--mlockall Call mlockall to lock current and future memory allocations and prevent being paged out -h|--help Display a short help message and options. CAVEATS
The pi_stress test threads run as SCHED_FIFO or SCHED_RR threads, which means that they can starve critical system threads. It is advisable to change the scheduling policy of critical system threads to be SCHED_FIFO prior to running pi_stress and use a priority of 10 or higher, to prevent those threads from being starved by the stress test. BUGS
No documented bugs. AUTHOR
Clark Williams <williams@redhat.com> Nov 27, 2006 pi_stress(8)