![]() |
|||
AROS Application Development ManualWarnung This document is not finished! It is highly likely that many parts are out-of-date, contain incorrect information or are simply missing altogether. If you want to help rectify this, please contact us. The Multitasking KernelBackgroundThere are two kinds of multitasking: Preemptive and Non-preemptive (also known as cooperative). Preemptive means that you get a certain amount of CPU time and then another task gets the CPU. Non-preemptive means that a task has to call a function which allows another task to run. Preemptive multitasking (PMT) has these advantages:
and these disadvantages:
Cooperative Multitasking (CMT) has these advantages:
and these disadvantages:
It seems obvious that CMT is better than PMT but that's not true. CMT is better when you have only a few tasks and a single user. Powerful OSes like Unix and AmigaOS have PMT because it's more simple to use. How does it work?The idea is pretty simple. Every computer has a clock and this clock can generate interrupts. An interrupt means that the CPU saves its current state on the stack of the current task and starts a special routine called the interrupt handler. Basically this handler now checks for other tasks which might want to run, selects one of them and switches the stack to the one of the newly chosen task. It then finishes and tells the CPU to continue where it was before the interrupt. Since the CPU is quite dumb, it will just load it's state from the new stack (ie. the one of the new task) and so the new task will run and the old one will be sleeping. Now let's have a look at the details. The life of a task looks like this: birth, waiting, running and dying. In computer terms, the task is created, then waits that it gets the CPU, does its work while it has the CPU (this might happen more than once) and at some stage, it terminates (or is terminated). It's more easy to understand how it all works when we begin with the time when one task loses the CPU and another one gets it. |
Copyright © 1995-2008, The AROS Development Team. All rights reserved. Amiga®, AmigaOS®, Workbench und Intuition sind eingetragene Warenzeichen von Amiga Inc. Alle anderen Warenzeichen gehören dem jeweiligen Besitzer. |