locking - Linux Kernel Preemption during spin_lock and mutex_lock -


when process in kernel space holding spin_lock, process cannot preempted due of following conditions :

  1. when time-slice of process gets exhausted
  2. when high priority process becomes runnable
  3. when interrupt occurs

however process can yield processor if blocks, sleeps, or explicitly call schedule(). understanding correct?

when process in kernel space holding mutex_lock, can process preempted due above conditions listed 1, 2 , 3.

current implementations of spin locks use 2 entirely separate mechanisms ensure mutual exclusion, 1 dealing inter-processor exclusion , 1 dealing local processor threads , interrupt handlers.

  • there spin_lock there provide mutex between 2 or more processor cores. processor hitting locked spin lock stuck until processor releases it. spin locks serve no purpose on single processor systems - other increase chance of total deadlock - removed @ kernel compile time.

  • to provide local processor mutex, spin_lock() calls preempt_disable() (on pre-emptive scheduling systems) prevent other thread running whilst lock held; spin_lock_irqsave() equivalent of local_irq_save() disable interrupts prevent else @ running on local processor.

as should obvious above, using spin locks can gum whole machine spin locks should used short periods of time , should never might cause reschedule whilst holding lock.

the case mutex_lock totally different - threads attempting access lock affected , if thread hits locked mutex reschedule occur. reason mutex_locks cannot used in interrupt (or other atomic) contexts.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -