Pre-emptive multitaskingPre-emptive multitasking
is a form of multitasking
, of sharing a computer's CPU
's processing time among 'tasks' (programs). In a pre-emptive multitasking operating system
, processes are not allowed to take an indefinitely long time to complete execution in the CPU. A process is alloted some fixed amount of time within which if the task is not complete it is pushed onto the stack and the next process in queue is loaded into the CPU. This pre-emption can occur due to hardware interrupts as well.
Sometimes certain tasks are given priority (there can be several levels of priority) so that they take a larger slice of time and are not made to wait in queue for long. When pre-empting, the processor's state (flags, registers and the instruction pointer) is saved to the memory. It must be reloaded into the processor for the code to get executed again.