Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • Nothing of this is done in hardware (except for the regular interrupt that the kernel uses to end the thread/process time slices). All of this is done by the kernel, manipulating kernel data structures. Commented Sep 30, 2017 at 18:59
  • Thanks for your response. Ok so it is done in the kernel. How does the kernel wake up a process? Is there an array of condition variables that the OS keep checking when it runs the tick interrupt? Commented Sep 30, 2017 at 19:01
  • 2
    A process/thread is woken up but inserting it in the queue of processes/threads to be scheduled. If you look at the source of signal, there is a user-space list of threads waiting on the conditional variable, and one of those gets woken with a futex system call. Checking an array of condition variables every tick would be very slow ... Commented Sep 30, 2017 at 19:18
  • 1
    Threads are implemented as a mix of userspace and kernel space. Just like a thread/process waiting on I/O is put on a kernel-space list to be rescheduled when that particular I/O operation completes, a thread waiting on a condition variable is put on a user-space list of this condition variable. So the answer to your question is "yes and no". :-) And the current thread implementation has been optimized over the years, so don't get hung up when the implementation doesn't match the (more simple) principles. Commented Sep 30, 2017 at 19:24
  • 2
    I think this is a great question, and it deserves an answer somewhere other than the comments, @dirkt :) Commented Feb 15, 2018 at 23:22