|
发表于 2005-10-14 11:46:59
|
显示全部楼层
[quote:0b87057b08="good02xaut"]
<<linux device drivers 3rd>>中对于spinlock有介绍的。
当对spinlock加锁时,如果获取不到共享资源,进程会发生死循环,决不释放CPU。
但可以在此时通过CPU的硬件中断,完成对共享资源的释放,从而解决死锁。[/quote]
原来是这样,刚看了LDD 3rd 第5章中有关spinlock的介绍才真正明白这是它是怎么一回事。
对于非SMP,非抢占式内核,spin相关的操作才会被设置为nop;
但对运行于单CPU的抢占式(preemption在编译是可配置)内核的并发处理仍然需要执行spinlock操作。
底下为相关说明的原文:
Spinlocks are, by their nature, intended for use on multiprocessor systems, although
a uniprocessor workstation running a preemptive kernel behaves like SMP, as far as
concurrency is concerned. If a nonpreemptive uniprocessor system ever went into a
spin on a lock, it would spin forever; no other thread would ever be able to obtain
the CPU to release the lock. For this reason, spinlock operations on uniprocessor systems
without preemption enabled are optimized to do nothing, with the exception of
the ones that change the IRQ masking status. Because of preemption, even if you
never expect your code to run on an SMP system, you still need to implement proper
locking. |
|