Messages in this thread | | | From | "Venkata Rajesh Velamakanni" <> | Subject | Query on SCHED_RR. | Date | Mon, 17 Jul 2000 19:51:54 +0530 |
| |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN"> <HTML> <HEAD>
<META content=text/html;charset=iso-8859-1 http-equiv=Content-Type> <META content='"MSHTML 4.72.3110.7"' name=GENERATOR> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT size=2>Hello All,</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>I have a query in setting thread priorities using SCHED_RR</FONT></DIV> <DIV><FONT size=2>and pthread_attr_setschedparam. Can any one please answer</FONT></DIV> <DIV><FONT size=2>my queries.</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>I have created a thread (thread1)by setting SCHED_RR as scheduling policy</FONT></DIV> <DIV><FONT size=2>and priority as 1. Then I created another thread (thread2) with the same </FONT></DIV> <DIV><FONT size=2>scheduling policy </FONT><FONT size=2>but with higher priority. My thread2 never got chance to </FONT></DIV> <DIV><FONT size=2>execute until my thread1 is exited. </FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>From this I understood that there are two bugs, which need to be fixed.</FONT></DIV> <DIV><FONT size=2></FONT><FONT color=#000000 size=2>Could you please clarify whether following are bugs or not. Or Am I missing</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT><FONT size=2>something?</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2>1. First one is with priority, though my second thread is of high priority it</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT><FONT size=2> never got chance until my thread1 is exited. </FONT></DIV> <DIV><FONT color=#000000 size=2></FONT><FONT size=2>2. Second one is with scheduling policy, though I am using SCHED_RR,</FONT></DIV> <DIV><FONT size=2> my second thread did not get the time slice. </FONT></DIV> <DIV><FONT size=2> </FONT></DIV> <DIV><FONT size=2></FONT><FONT color=#000000 size=2>Following is the sample program:</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT><FONT size=2>----------------------------------------</FONT></DIV> <DIV><FONT size=2>------------------------------------------------------------------------------------------</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2>#include<stdio.h><BR>#include<pthread.h><BR>#include<errno.h><BR>#include<sched.h></FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2>void *test1() {<BR>int i;</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2>for ( i=0;i<1500000;i++)<BR> printf("..............\n");<BR> printf("Exiting test1 thread:%d");</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2>}</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2>void *test2() {<BR>int j;</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2>for(j=0;j<1500000;j++)<BR> printf("===================\n");<BR> printf("Exiting test2 thread:\n");<BR>}</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2><BR>main()<BR>{<BR> int th1,th2;<BR> pthread_t thread1,thread2;<BR> pthread_attr_t attr1,attr2;<BR> struct sched_param param1,param2;</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2> pthread_attr_init(&attr1);<BR> pthread_attr_init(&attr2);</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2> pthread_attr_setschedpolicy(&attr1, SCHED_RR);<BR> pthread_attr_setschedpolicy(&attr2, SCHED_RR);</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT color=#000000 size=2> param1.sched_priority = 1;<BR> param2.sched_priority = 99;</FONT></DIV> <DIV><FONT color=#000000 size=2></FONT> </DIV> <DIV><FONT size=2>if ( pthread_attr_setschedparam(&attr1, &param1) != 0 ) {</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2> printf("pthread_attr_setschedparam failed");<BR> perror("pthread_attr_setschedparam");<BR>}</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2> if ( pthread_attr_setschedparam(&attr2, &param2) != 0 ) {</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2> printf("pthread_attr_setschedparam failed");<BR> perror("pthread_attr_setschedparam");<BR>}</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>th1 = pthread_create(&thread1,&attr1, test1, NULL);<BR>th2 = pthread_create(&thread2,&attr2, test2, NULL);</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2><BR> printf("Waiting for thread1, thread2 to exit\n");<BR> pthread_join(thread1, NULL);<BR> pthread_join(thread2, NULL);</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>printf("Main program exited normally\n");</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2>}<BR></FONT></DIV> <DIV><FONT size=2></FONT><FONT color=#000000 size=2>--------------------------------------------------------------------------------------------------</FONT></DIV> <DIV><FONT size=2></FONT> </DIV> <DIV><FONT size=2></FONT> </DIV></BODY></HTML>
| |