1.前言
为什么要考虑内核同步
在单一CPU 的情况下,中断或者内核代码明确调度时,多个执行线程并发访问共享数据。目前多处理器以及抢占式内核的存在,更需要注意保护共享资源。
造成并发的原因
- Interrupts— An interrupt can occur asynchronously at almost any time, interrupting the currently executing code.
- Softirqs and tasklets— The kernel can raise or schedule a softirq or tasklet at
almost any time, interrupting the currently executing code.
- Kernel preemption— Because the kernel is preemptive, one task in the kernel
can preempt another.
- Sleeping and synchronization with user-space— A task in the kernel can
sleep and thus invoke the scheduler, resulting in the running of a new process.
- Symmetrical multiprocessing— Two or more processors can execute kernel
code at exactly the same time.
临界区
临界区( Critical Regions ) 指的是访问内存中共享数据的 代码段,编程者需要