Why spinlocks don't work in uniprocessor (unicore) systems?

前端 未结 5 1997
生来不讨喜
生来不讨喜 2020-12-23 23:55

I know that spinlocks work with spining, different kernel paths exist and Kernels are preemptive, so why spinlocks don\'t work in uniprocessor systems? (for example, in Linu

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 00:36

    The nature of a spinlock is that it does not deschedule the process - instead it spins until the process acquires the lock.

    On a uniprocessor, it will either immediately acquire the lock or it will spin forever - if the lock is contended, then there will never be an opportunity for the process which currently holds the resource to give it up. Spinlocks are only useful when another process can execute while one is spinning on the lock - which means multiprocessor systems.

提交回复
热议问题