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

前端 未结 5 1971
生来不讨喜
生来不讨喜 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:29

    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.

    Ref:Linux device drivers By Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartma

提交回复
热议问题