<div dir="ltr">Is not changing the state to TASK_INTERRUPTIBLE before calling schedule() renders it not-schedulable? I thought task would be removed off run-queue by schedule() because it is in TASK_INTERRUPTIBLE state. <div>
<br></div><div>I was making a sort of task queue. Threads puts themselves into this queue when a resource(say memory-space) is not available. And other thread, post releasing the memory space, will wake the first thread in queue.</div>
<div>There are other means to achieve that, but I wondered why the above mentioned method did not succeed in making thread sleep.</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jun 11, 2014 at 11:21 PM,  <span dir="ltr">&lt;<a href="mailto:Valdis.Kletnieks@vt.edu" target="_blank">Valdis.Kletnieks@vt.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Wed, 11 Jun 2014 23:09:05 +0530, Joshi said:<br>
<br>
&gt; set_current_state (TASK_INTERRUPTIBLE);<br>
&gt; schedule ();<br>
&gt;<br>
&gt; Is this a sure-shot way of putting a thread to sleep, or are there<br>
&gt; conditions when this may not put the calling thread into sleep?<br>
<br>
</div>This will only succeed in guaranteeing the thread sleep if the thread has done<br>
something *else* to render it not schedulable.  schedule() will<br>
return right back to that thread if it&#39;s the highest-priority thing<br>
that&#39;s runnable.<br>
<br>
What problem are you trying to solve?  Usually, you do that sort of<br>
schedule() when you&#39;re doing something that will take a relatively long<br>
chunk of time, and want other things to have a *chance* of running.  But<br>
usually, you&#39;re perfectly happy with continuing to run if nobody else<br>
wants to run.<br>
<br>
Why did you want a guaranteed sleep?  If it&#39;s because you&#39;ve started an<br>
I/O and you *know* it will be 125 milliseconds before you can make further<br>
progress, there&#39;s mdelay() and similar APIs... and so on for other reasons<br>
for wanting to sleep (for instance, blocking on a lock has an API, etc)<br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Joshi<br>
</div>