Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 12368

Wait queue and race condition

$
0
0

I'm reading "Linux Kernel Development" by Rovert Love and found the code below to wait for an event.

DEFINE_WAIT(wait);add_wait_queue(q, &wait); while (!condition) {    // What happens if condition is changed and wake_up() is called here ?    prepare_to_wait(&q, &wait, TASK_INTERRUPTIBLE);     if (signal_pending(current))        /* handle signal */     schedule();}finish_wait(&q, &wait);

My question is as in the code above. What happens if condition is changed and wake_up() is called after condition check but before prepare_to_wait?My (probably wrong) interpretation here is that because prepare_to_wait makes the thread TASK_INTERRUPTIBLE and calles schedule() after the condition is changed, it sleeps forever (unless it gets signaled or another wake_up is called).


Viewing all articles
Browse latest Browse all 12368

Trending Articles



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