title: Using wait_event_interruptible and wake_up_all together
body: <p>For a class project involving scheduling processes using blocking and locks, we're supposed to use two kernel functions:</p>
  <pre><code>int wait_event_interruptible(wait_queue_head_t q, CONDITION);
  void wake_up_all(wait_queue_head_t *q); 
  </code></pre>
  <p>The explanation of wait_event_interruptible is:</p>
  <blockquote>
  <p>Blocks the current task on a wait queue until a CONDITION becomes true.</p>
  <p>This is actually a macro. It repeatedly evaluates the CONDITION, which is a fragment of C code such as foo == bar or function() &gt; 3. Once the condition is true, wait_event_interruptible returns 0. If the condition is false, the current task is added to the wait_queue_head_t list with state TASK_INTERRUPTIBLE; the current process will block until wake_up_all(&amp;q) is called, then it will re-check the CONDITION. If the current task receives a signal before CONDITION becomes true, the macro returns -ERESTARTSYS.</p>
  </blockquote>
  <p>And the explanation of wake_up_all is:</p>
  <blockquote>
  <p>Wake up all tasks in the wait queue by setting their states to TASK_RUNNABLE.</p>
  </blockquote>
  <p>I'm having a hard time figuring out how exactly these functions work and how to use them together.  For example, when does the CONDITION get checked?  Does wait_event_interruptible continuously poll, or does it only recheck the condition when wake_up_all is called?  This explanation is a little unclear.</p>
  <p>If you could give an example of how to use these functions together that would be very helpful.</p>