http://www.aros.orgAROS-ExecTeam AROSAROS-Exec Archives

Home

English

Česky

Deutsch

Ελληυικά

Français

Italiano

Nederlands

Polski

Português

Русский

Español

Suomi

Svenska


Nyheter

Arkiv

Introduktion

Status
Skärmdumpar
Portningar
Licens

Nerladdning


Dokumentation

Användare
Installation
Användning
Shell commands
Applications
Frågor och svar
Utvecklare
Medverka
Roadmap
Bug Tracker
Arbeta med Subversion
Kompilering
Manual för applikationsutveckling
Manual för Zune applikationsutveckling
Manual för systemutveckling
Manual för debugging
Referens
Specifikationer
UI Style Guide
Dokumentering
Porting
Översättning
Sammanfattningar
Länkar

Kontakt

Mailing listor
IRC-kanaler

Medverkande

Acknowledgements


Bilder

Utvecklare
Utvecklare en Masse

Sponsorer

Länkning

Länkar

SourceForge Logo

AROS Application Development Manual

Index

Varning

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 Kernel

Background

There 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:

  • It's simple to understand
  • There is no need to make sure that your task doesn't keep the CPU forever.

and these disadvantages:

  • It's complicated to exchange data with other tasks
  • You never know how long you will stay awake
  • The OS must decide which task to run next in a clever way

Cooperative Multitasking (CMT) has these advantages:

  • It's very simple to implement
  • It's easy to exchange data
  • You know exactly how long you will stay awake
  • You get most of the CPU

and these disadvantages:

  • If a task behaves badly, there is no way to stop it (for example if it keeps the CPU forever, all you can do is turn the computer off).
  • It's hard to make sure that every task gets the CPU now and then

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. Alla rättigheter förbehålles.
Amiga®, AmigaOS®, Workbench och Intuition är varumärken som tillhör Amiga Inc. Alla andra varumärken tillhör sina respektive ägare.