Thread Scheduling using POSIX THREAD
I have done whatever u mentioned. The code looks as follows.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
void *tf1(void *arg);
void *tf2(void *arg);
void *tf3(void *arg);
char m1[] = " Thread1";
char m2[] = " Thread2";
char m3[] = " Thread3";
struct sched_param schedparam1,schedparam2,schedparam3;
int main() {
int res,max_priority,min_priority;
pthread_t t1,t2,t3;
pthread_attr_t at1,at2,at3;
schedparam1.sched_priority = 40;
schedparam2.sched_priority = 60;
schedparam3.sched_priority = 80;
/* Set attributes*/
pthread_attr_init(&at1);
pthread_attr_setinheritsched(&at1, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&at1, SCHED_OTHER);
pthread_attr_setschedparam(&at1, &schedparam1);
// I have done the same for other threads
max_priority=sched_get_priority_max(SCHED_OTHER);
min_priority=sched_get_priority_min(SCHED_OTHER);
printf(" MAX is %d and Min is %d\n",max_priority,min_priority);
printf("$$$$$$$$$$$$$$$$$$$$$$$$\n");
//Thread creatiom
res = pthread_create(&t1, &at1, tf1, (void *)m1);
res = pthread_create(&t2, &at2, tf2, (void *)m2);
res = pthread_create(&t3, &at3, tf3, (void *)m3);
}
void *tf1(void *arg) {
printf("tf1 is running. Argument was %s\n", (char *)arg);
sleep(3);
strcpy(m1, "thread1 left");
pthread_exit("...........T1");
}
//tf2 tf3
Iam getting Max and Min priority as zero.How can i modify this to get the threads scheduled . How can I get the header file info about Pthread library.
|