lkml.org 
[lkml]   [2000]   [Jul]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectQuery on SCHED_RR.
Date
<!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>&nbsp;</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>&nbsp;</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&nbsp;</FONT></DIV>
<DIV><FONT size=2>execute until my thread1 is exited. </FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</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>&nbsp;</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>&nbsp;&nbsp;&nbsp; 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>&nbsp;&nbsp;&nbsp; my second thread did not get the time
slice.&nbsp;</FONT></DIV>
<DIV><FONT size=2>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT color=#000000
size=2>#include&lt;stdio.h&gt;<BR>#include&lt;pthread.h&gt;<BR>#include&lt;errno.h&gt;<BR>#include&lt;sched.h&gt;</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>void *test1() {<BR>int i;</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>for (
i=0;i&lt;1500000;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
printf(&quot;..............\n&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
printf(&quot;Exiting test1 thread:%d&quot;);</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>}</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>void *test2() {<BR>int j;</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000
size=2>for(j=0;j&lt;1500000;j++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
printf(&quot;===================\n&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
printf(&quot;Exiting test2 thread:\n&quot;);<BR>}</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2><BR>main()<BR>{<BR>&nbsp; int th1,th2;<BR>&nbsp;
pthread_t thread1,thread2;<BR>&nbsp; pthread_attr_t attr1,attr2;<BR>&nbsp;
struct sched_param param1,param2;</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>&nbsp; pthread_attr_init(&amp;attr1);<BR>&nbsp;
pthread_attr_init(&amp;attr2);</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>&nbsp;pthread_attr_setschedpolicy(&amp;attr1,
SCHED_RR);<BR>&nbsp;pthread_attr_setschedpolicy(&amp;attr2,
SCHED_RR);</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=2>&nbsp;param1.sched_priority =
1;<BR>&nbsp;param2.sched_priority = 99;</FONT></DIV>
<DIV><FONT color=#000000 size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>if ( pthread_attr_setschedparam(&amp;attr1, &amp;param1) != 0
) {</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
printf(&quot;pthread_attr_setschedparam
failed&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
perror(&quot;pthread_attr_setschedparam&quot;);<BR>}</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;if ( pthread_attr_setschedparam(&amp;attr2, &amp;param2)
!= 0 ) {</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
printf(&quot;pthread_attr_setschedparam
failed&quot;);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
perror(&quot;pthread_attr_setschedparam&quot;);<BR>}</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>th1 = pthread_create(&amp;thread1,&amp;attr1, test1,
NULL);<BR>th2 = pthread_create(&amp;thread2,&amp;attr2, test2,
NULL);</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2><BR>&nbsp; printf(&quot;Waiting for thread1, thread2 to
exit\n&quot;);<BR>&nbsp; pthread_join(thread1, NULL);<BR>&nbsp;
pthread_join(thread2, NULL);</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>printf(&quot;Main program exited
normally\n&quot;);</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV></BODY></HTML>
\
 
 \ /
  Last update: 2005-03-22 13:57    [W:2.002 / U:0.444 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site