- 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 (merged 2.6.25)
|188.8.131.52. Mutexes||1. Denx Training Topics||184.108.40.206. Other locking techniques|