Search code examples
kernelspinlockpreemption

why spin_lock should disable preempt? if not disable preempt what will happend?


For this situation: Process B will wait Process A release spin,so preemt OK ??? Process A: -->spin lock --> do strict call --> before unlock time int Time int ISR: --> Process A time slice finished --> need schedule -->ISR ret --> schedule to Process B Process B: -->spin lock for same resource --> failed --> spin wait


Solution

  • In the situation you provided Process B will busy wait until its slice ends and rescheduling to Process A occures. So, whole time slice would be a wasting of the time.

    Things may be worse if switching from Process B to Process A is never occures. E.g., if priority of the Process B is more than one of the Process A. In that case it is deadlock.

    Disabling preemption in spin_lock protects from both wasting of time and deadlock described above.