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
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.
