Do you really "sleep" when blocked on a mutex?

Julian Elischer julian at
Mon Apr 21 22:50:22 UTC 2008

Murty, Ravi wrote:
> That's actually what I was trying to get to.
> If I look at vm_daemon(), it checks to see if every thread of the
> process is running, on the runq or sleeping. If any threads fails the
> condition - and I can think of the case where a thread is blocked
> waiting for a lock - it is not a target to be swapped out. I guess this
> means that if a thread is holding a lock, it can be swapped out.

no. because if it holds a lock it must be in the run queue, running or 
waiting for another lock. no other state is permitted.

> How
> does this guarantee that the thread is not holding a kernel lock? Why
> don't they allow threads waiting for a lock (blocked threads/processes)
> to be swapped out?
> Related question: how can a process/thread running on a CPU be swapped
> out, do they suspend the threads before they pull out memory from
> underneath them?

not sure, I'd have to read the code again.

> Thanks
> Ravi

More information about the freebsd-hackers mailing list