From: mlevis@ringer.cs.utsa.edu (Mike Levis)
Newsgroups: comp.os.os2.misc
Subject: Re: preemptive multi-tasking
Date: 15 Apr 92 00:59:12 GMT
Organization: University of Texas at San Antonio

In article <2097@nlsun1.oracle.nl> dhanna@nl.oracle.com (Damien Hanna) writes:
>Just a brief point please. Time sliced multi-tasking IS preemptive. Preemption
>means a running process in interupted somehow by the operating system. The
>algorithms it uses to prioritise tasks is irrelevant. OS/2 uses time slicing 
>the same as every other MT operating system. It interrupts a task (preempts) and
>allows it to run for a fixed period (time slices) and then preempts again. I 
>dont know what the confusion over this point is. There was no such thing as
>co-operative MT before WINDOWS. Preemption is a word that seems to have grown
>up around OS/2 to distinguish its task managemnt from WINDOWS.
>
>DesqView & WINDOWS 3.0 (Enhanced Mode) and pre-emptive systems. I get the 
>feeling the guy (Bill ?) who started this has realised he blundered his 
>original post and is now trying to cover this ass with semantics.
>
>This is not a flame BTW, just stating the facts.
>
>Damien.

Time-sliced multi-tasking has NOTHING to do with preemption.
In fact there are several forms of time-sliced multi-tasking
(as opposed to Shortest Job First, or First In First Out
multi-tasking).  Here are the real facts:

   Round-robin multitasking:
      Each process is given a quantum (time slice) to execute instructions.
      Each process takes turns receiving a quantum equally.
      A running process loses the CPU _only_ when its quantum expires.
      A process does not gain CPU access again until all ready
         processes receive CPU access.

   Multi-level Feedback Queue (what OS/2 and Unix uses) multitasking:
      Each process is given a quantum (time slice) to execute instructions.
      A running process loses the CPU _only_ when its quantum expires.
      A process does not gain CPU access again until all ready
         processes IN A QUEUE OF A HIGHER PRIORITY have terminated.
         However, to avoid starvation, a ready process can be moved
         to a higher priority queue if it has not received a quantum
         for a certain period of time.

These are only two methods of multitasking.  What does it have to do
with pre-emptive multitasking?  NOTHING!!!!   However, a time-sliced
multitasking algorithm can be made pre-emptive.  This means that a
running process loses the CPU when its quantum expires, or it accesses
a device port.  It also means that a running process can be interrupted
if a process with a higher priority gets placed in the ready queue.

When accessing a device port, the running process can be "blocked" by
being put in a waiting queue (depending on the implementation). Once the
device has completed, the first process in the waiting queue
(for that device) gets put back on the ready queue. At this point,
a running process may be pre-empted if it has a lower priority than
the wakened process.

Here is an example of Round-robin without and with pre-emption, using
two processes for time t(0) through t(n):

   without pre-emption:
      t(0) process 1 quantum
      t(1) process 2 quantum
      t(2) process 1 quantum, accesses comm port and waits
      t(3) process 2 quantum
      t(4) process 1 quantum, still waiting for comm port
      t(5) process 2 quantum
      t(6) process 1 quantum, still waiting for comm port
      ...
      t(n) process 1 quantum, comm port finished
      ...

   with pre-emption:
      t(0) process 1 quantum
      t(1) process 2 quantum
      t(2) process 1 quantum, accesses comm port, gets put in waiting queue 
      t(3) process 2 quantum
      t(4) process 2 quantum
      t(5) process 2 quantum
      t(6) process 2 quantum
      ...
      t(n) process 1 quantum, wakened since comm port is finished
      ...

Notice that without pre-emption, process 1 uses CPU time even
thought it is not using the CPU (it is waiting for the comm port).
Notice that with pre-emption, process 1 does not use CPU time since
it is in the waiting queue, not ready queue.  Also, process 2 runs
faster since it gets the CPU to itself!

This is not a flame BTW, just stating the facts.

BTW, BIOS uses cooperative multitasking when it uses INT 09 (keyboard)
and INT 08 (timer update).  This means that the interrupt handler
keeps control of the CPU until it wants to finish.  Keep in mind that
interrupts are disabled upon an INT unless the handler uses STI.

-------------------------------------------------------------------------
Mike Levis		Reader of the OS/2 Frequently Asked Questions List

Point: "Timothy Sipples for U.S. President!!!!"
Counter-point: "But if he is President, who will help us with OS/2?!" ;-)
Newsgroups: comp.os.os2.misc