In multiprocessor mode, the context switch can certainly occur during the execution of the interrupt handler. In fact, it will be difficult to prevent.
On a single processor machine, by definition, only one control thread can run at a time. It has only one set of registers, one ALU, etc. Therefore, if the interrupt handler works, there simply are no resources to execute the context switch.
Now, if you mean, can the interrupt handler actually call the context switch code and do this, well, I suppose, on some systems that can be made to work. But for most, this would not be of great value and would be difficult to organize. The CPU operates with a higher priority, and this priority cannot be reduced or the synchronization between interrupt levels is lost. Critical sections in the OS are already synchronized with the execution of interrupts, and this will create difficulties. In addition, the context switch occurs by changing the stacks, as in a program with streaming user mode, so it is difficult to imagine how this can happen when the interrupt stack is needed to return from the interrupt.
source share