Query on SCHED_RR.

From: Venkata Rajesh Velamakanni (rajesh.venkata@wipro.com)
Date: Mon Jul 17 2000 - 09:21:54 EST


Hello All,

I have a query in setting thread priorities using SCHED_RR
and pthread_attr_setschedparam. Can any one please answer
my queries.

I have created a thread (thread1)by setting SCHED_RR as scheduling policy
and priority as 1. Then I created another thread (thread2) with the same
scheduling policy but with higher priority. My thread2 never got chance to
execute until my thread1 is exited.

>From this I understood that there are two bugs, which need to be fixed.
Could you please clarify whether following are bugs or not. Or Am I missing
something?

1. First one is with priority, though my second thread is of high priority it
    never got chance until my thread1 is exited.
2. Second one is with scheduling policy, though I am using SCHED_RR,
    my second thread did not get the time slice.
 
Following is the sample program:
----------------------------------------
------------------------------------------------------------------------------------------

#include<stdio.h>
#include<pthread.h>
#include<errno.h>
#include<sched.h>

void *test1() {
int i;

for ( i=0;i<1500000;i++)
        printf("..............\n");
        printf("Exiting test1 thread:%d");

}

void *test2() {
int j;

for(j=0;j<1500000;j++)
        printf("===================\n");
        printf("Exiting test2 thread:\n");
}

main()
{
  int th1,th2;
  pthread_t thread1,thread2;
  pthread_attr_t attr1,attr2;
  struct sched_param param1,param2;

  pthread_attr_init(&attr1);
  pthread_attr_init(&attr2);

 pthread_attr_setschedpolicy(&attr1, SCHED_RR);
 pthread_attr_setschedpolicy(&attr2, SCHED_RR);

 param1.sched_priority = 1;
 param2.sched_priority = 99;

if ( pthread_attr_setschedparam(&attr1, &param1) != 0 ) {

        printf("pthread_attr_setschedparam failed");
        perror("pthread_attr_setschedparam");
}

 if ( pthread_attr_setschedparam(&attr2, &param2) != 0 ) {

        printf("pthread_attr_setschedparam failed");
        perror("pthread_attr_setschedparam");
}

th1 = pthread_create(&thread1,&attr1, test1, NULL);
th2 = pthread_create(&thread2,&attr2, test2, NULL);

  printf("Waiting for thread1, thread2 to exit\n");
  pthread_join(thread1, NULL);
  pthread_join(thread2, NULL);

printf("Main program exited normally\n");

}

--------------------------------------------------------------------------------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Jul 23 2000 - 21:00:09 EST