I want some clarification regarding mutex and semaphore.
My question is,
Waiting, sleeping, blocking, all mean the same thing:
The thread makes a system call (get a mutex or semaphore, wait for some time, whatever)
The OS takes control, run the scheduler, marks the thread as waiting for a resource, updates status of other threads as well, then gives control to a thread that is ready to run. If more than one thread is ready to run, one is selected according to scheduling policy.
As soon as the resource is made available (through another system call made by another thread), the scheduler updates the status of the former thread from waiting for a resource to ready to run and the thread is given control as soon as the scheduler policy decides so.
As long as the thread is waiting for a resource, it doesn't consume CPU. There is no polling from its part.