When is to preempt safe?

Parmenides mobile.parmenides at gmail.com
Sat Oct 8 12:24:23 EDT 2011


2011/10/8 Michael Blizek <michi1 at michaelblizek.twilightparadox.com>:
> Hi!
>
> There are 2 different kind of locks: Those which can be preempted (mutex and
> semaphores) and those which cannot (spinlocks). Spinlocks do busy waiting
> until the lock is released. On single cpu systems, the are optimised into
> enable/disable preemption. Spinlocks have to be used if the data it protects
> is partly accessed in code paths which have preemption disables for other
> reasons (e.g. being interrupt handler). This is because otherwise you have a
> problem if you cannot preempt, but need to aquire a lock which is held by a
> "thread" which has been preempted.
>

Except for interrupt handler, is there any other code path which
cannot be preempted but need to obtain a lock. If not, I think a
thread holding a spinlock can disable interrupt when it is in critical
section to resolve this problem, rather than disable preemption.



More information about the Kernelnewbies mailing list