Linux Concurrency and race conditions
时间:2007-07-01 来源:jack_zheng
1. sources of concurrency(race conditions)
- multiple user-space processes
- SMP
- preempible kernel code
- device interrupts
- delayed code execution mechanism, such as workqueues, taksklets and timers.
- hot-pluugable
2. Semaphores
Semaphores are used for mutual exlusion. can be used when slepps are a possibility.
==> Reader/Writer Semaphores
3. Spinlocks
Spinlocks may be used in code that cannot sleep. Performance is higher than semaphores when properly used.
- Any time kernel code holds a spinlock, preemption is disable on the relevant processor.
- Disable interrupts while spinlock is held.
- spinlock mus always be held for the minimum time possible.
==> Reader/Writer spinlocks
4. Alternatives to Locking
1) Lock free algorithms
circular buffer
2) Atomic variables
you should not count on an atomic_t holding more than 24 bits.
3) Bit Operations
4) seqlock
5) read-copy-update
ldd3-ch5
相关阅读 更多 +










