- fast, busy waiting mutual exclusion mechanism
- Atomic variable is initalized to 1: available
spin_lock()atomically decrements value and checks if equals 0
- if yes: lock obtained
- if no: no lock, spin in tight loop until value is 1
spin_unlock()sets value back to 1
- must only be used in code that cannot sleep!
- no userspace memory access
- no memory allocation (except
- three flavors
- on UP, no preemption: optimized out
- on UP with preemption: disable preemption
- protects against concurrency with "regular" kernel code
- disables interrupts on local CPU
- protects against concurrency with interrupt handlers
- disables soft interrupt on local CPU
- protects against concurrency with bottom halves, tasklets, softirqs, ...
- fast and simple
- code must be atomic: can never sleep!
- unfair! solution: ticket spinlocks (2.6.25)
|22.214.171.124. Mutexes||1. Denx Training Topics||126.96.36.199. Other locking techniques|