Why do you need to disable interrupts when synchornizing code in kernel?
For example, in the following code taken from the linux schedule() function:
need_resched:
prev = current;
rq = this_rq();
**spin_lock_irq(&rq->lock);** //disables interrupts
switch (prev->state) {
case TASK_INTERRUPTIBLE:
if (unlikely(signal_pending(prev))) {
prev->state = TASK_RUNNING;
break;
}
default:
deactivate_task(prev, rq);
case TASK_RUNNING:
;
}
The spin_lock_irq() function disables interrupts, but why is it needed? Suppose I don't disable interrupts, and an interrupt comes, so I'll just handle it and come back to the scheduler and resume what I was doing.