Quantcast
Channel: User rmn - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Sleeping in the kernel using set_current_state

$
0
0

I've been reading http://www.linuxjournal.com/article/8144 and thinking about the following situation:

4253  /* Wait for kthread_stop */4254  set_current_state(TASK_INTERRUPTIBLE);4255  while (!kthread_should_stop()) {4256          schedule();4257          set_current_state(TASK_INTERRUPTIBLE);4258  }4259  set_current_state(TASK_RUNNING);4260 return 0;

Now, what happens if kthread_stop was called right before line 4254 where we set the process to sleep, and right after that line we actually get preempted/scheduled and the process is also really sent to sleep?

In this case, the wake up call is received right before changing the state (so it does not affect us), and the normal operation of the operating system puts us to sleep before we actually check anything.

I imagine I'm missing something, probably one of the following two options:(1) The actual change of the state only happens when we call schedule(), or (2) There is no way for us to get scheduled out (either by preemption, interrupts, anything) after the set_current_state call and before the schedule() call.

Thanks for any assistance!


Viewing all articles
Browse latest Browse all 39

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>