|
原帖由 corba 于 2005-7-16 13:18 发表
何为system context ? 何为interrupt context?他们的意义是什么呢?spinlocks是何解?它和semaphoore的区别又在何处?
希望大家不闵回答,说出一个也好,在此先谢过。
http://www.cis.temple.edu/~ingargio/cis307/readings/spinsem.html
Spinlocks are abstract data types, or classes, that support a Busy-Wait solution for the Mutual Exclusion Problem。
People use the term "Semaphore" to refer to a variety of synchronization mechanisms. Here by "Semaphore" we mean the "non-busy-waiting" analog of SpinLocks.
*Spinlocks implement a "busy wait condition" for a resource. If a processor attempts to obtain a spinlock being held by another processor, it will wait until the lock is released.
Spinlocks can be acquired on an interrupt stack. A deadlock can arise, however, if a processor takes an interrupt while holding a spinlock and the interrupt code tries to acquire the same spinlock. To prevent this from occurring, HP-UX requires the spl level to be raised whenever a spinlock is acquired. When the spinlock is released, the prior spl level is reverted to. Once a spinlock is acquired, the spl level should not be lowered within the spinlocked critical section.
Spinlocks are used to synchronize access to data between multiple processors, and as such, have little value in a uniprocessor system. Within the kernel the MP_SPINLOCK() macro checks the uniprocessor flag and returns if not an MP system.
* Kernel semaphores control access through blocking strategies. With blocking semaphores, a processor attempting to acquire a semaphore already held by another processor will put its current thread to sleep and context switch to another task.
Semaphores are used to provide mutual exclusion or to synchronize access between multiple processes or threads, regardless of how many processors there are.
[ 本帖最后由 asdfgh 于 2005-7-19 16:46 编辑 ] |
|