What is preemptive multitasking?
What is preemptive multitasking? After googling it I couldn't find an answer can some开发者_JS百科one help me?
http://en.wikipedia.org/wiki/Preemption_(computing)
Read the Wikipedia article. Think of it this way, it is a way to allow you to run many different programs at once without each program needing to have been written to give up the processor's time - the OS handles it. The idea is that each process is "preempted" at some point.
simply if a process is a preemptive then it can be stopped and send to ready queue by external interruption(trap).
- When a process switches from the running state to the waiting state (for example, as the result of an I/O request or an invocation of wait() for the termination of a child process)
- When a process switches from the running state to the ready state (for example, when an interrupt occurs)
- When a process switches from the waiting state to the ready state (for example, at completion of I/O)
- When a process terminates
For situations 1 and 4,there is not-preemptive
Preemptive Multitasking requires two main components: A timer interrupt ( say every 10 msec ) and a scheduler which is 'Connected' to that interrupt. The scheduler then saves the 'context' of the "interrupted/preempted" task ( which is fancy term for all the registers/stack pointer) in some area ( like stack) and then determines via its scheduling algorithm which ( other) task can "run" next. If it finds one, it unwinds/restores the context for THAT task and returns from the timer interrupt. BTW, just like a "call" which places the return address ( usually the address after the Call instruction on the stack, an interrupt works the same way and when an interrupt "returns" it uses what is on the stack an jumps to it. So when we're returning from some other task to its 'interrupt' point we just have to manipulate the stack, and place the return address from THAT task on the TOP of the stack and do an "Return-from_Interrupt" instruction. Different from normal return. I bet you're now sorry you asked ! Cheers,
精彩评论