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
thr_getprio(3C) 					   Standard C Library Functions 					   thr_getprio(3C)

NAME
thr_getprio, thr_setprio - access dynamic thread scheduling SYNOPSIS
cc -mt [ flag... ] file...[ library... ] #include <thread.h> int thr_setprio(thread_t target_thread, int priority); int thr_getprio(thread_t target_thread, int *priority); DESCRIPTION
The thr_setprio() function dynamically changes the priority of the thread specified by target_thread within the current process to the pri- ority specified by priority. By default, threads contend for synchronization objects based on fixed priorities that range from 0, the least significant, to 127. The target_thread will receive precedence by libthread over lower priority threads with respect to synchro- nization object contention. The thr_getprio() function stores the current priority for the thread specified by target_thread in the location pointed to by priority. Thread priorities regulate the order in which threads unblock from synchronization objects and are different from realtime priorities, which regulate and enforce access to CPU resources. Programs that need access to "real" priorities should use bound threads in the realtime class (see priocntl(2)). RETURN VALUES
If successful, the thr_getprio() and thr_setprio() return 0. Otherwise, an error number is returned to indicate the error. ERRORS
For each of the following conditions, these functions return an error number if the condition is detected. ESRCH The value specified by target_thread does not refer to an existing thread. The thr_getprio() and thr_setprio() functions may fail if: EINVAL The value of priority makes no sense for the scheduling class associated with the target_thread. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
priocntl(2), sched_setparam(3RT), thr_create(3C), thr_suspend(3C), thr_yield(3C), attributes(5), standards(5) SunOS 5.10 22 Mar 2001 thr_getprio(3C)