|
|
Log in / Subscribe / Register

Silly question time

Silly question time

Posted Jan 9, 2015 2:21 UTC (Fri) by koverstreet (subscriber, #4296)
In reply to: Silly question time by Max.Hyre
Parent article: The problem with nested sleeping primitives

Because code doesn't just call schedule() - it changes the task state to something other than TASK_RUNNING, so that once they call schedule() the scheduler won't run them a second time until someone else wakes them up.

If you change that to

if (condition)
break;
set_current_state(TASK_UNINTERRUTIBLE);
schedule();

what happens if the condition becoming true and the wakeup happens after checking the condition, but before setting the task state? See the issue?

The solution is to set the task state to TASK_UNINTERRUTIBLE _before_ checking the condition. Then if the wakeup comes between checking the condition and the schedule(), the task state still gets set back to TASK_RUNNING and the task won't sleep forever.


to post comments


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds