Page 1 of 1

Multitasking???

Posted: Thu Oct 14, 2004 7:23 am
by KieranFoot
In operating multitasking operating systems if one program crashes the system can keep on running, right?

How does this work...

As far as i know multitasking can be described in a series of steps:-
  • Save current system registers
  • Load tasks registers
  • Run x bytes of task code
  • Save tasks registers
  • Load saved system registers
  • Return to system for next task call
Is this right ???

If so i cannot see how a crash protection mechanism would work... ::)

Re:Multitasking???

Posted: Thu Oct 14, 2004 7:50 am
by crc
In operating multitasking operating systems if one program crashes the system can keep on running, right?
That's not right. If everything runs in the same ring, any process can crash the entire system. Using ring0 for kernel and ring3 for apps should improve the overall stability IIRC.

Re:Multitasking???

Posted: Thu Oct 14, 2004 10:01 am
by Pype.Clicker
Multitasking doesn't imply a program can run independently of other programs. Multiprogramming (e.g. using multitasking and multiple address space, giving each program a separate memory space and a separate 'processor state') more or less help, but not necessarily.

A program that crash may leave files locked, shared things in invalid states, etc. It does not automatically crash the whole system with it, but it can lead much of the system in an incoherent state.

Multitasking simply means that if a program is *blocked* because waiting for something, it usually doesn't block other programs along, and thus the system can go on with (other) useful job.

Re:Multitasking???

Posted: Fri Oct 15, 2004 6:43 am
by Solar
I think KieranFoot's non-understanding sits at a deeper level: memory protection...

Modern CPU's contain an auxiliary feature called a "Memory Management Unit". This part of the CPU provides a mapping from "virtual addresses" (used by the running process) to "physical addresses" (i.e., actually existing RAM addresses).

Since every running task gets its own, non-overlapping memory map, a crashing task cannot damage another task since it cannot "see" the other task at all.

That taken into account, your list would look like:

* save current system registers;
* point MMU to new tasks' memory map;
* load new task's registers;
* run x bytes of task code;
* repeat.

This is grossly oversimplified, but should give an idea of how tasks can be protected from each other. Any communication between tasks is done via the kernel (which is the only part of the system "seeing" all tasks).

Re:Multitasking???

Posted: Fri Oct 15, 2004 6:54 am
by distantvoices
@solar:
I beg your pardon, and acknowledge herewith that you have said "grossly oversimplyfied". Nevertheless:

it should be, if we wanna do multi*threading*, in a way like this:

if(tcb->memory_map!=cpu->memory_map)point_cpu_to_memorymap(tcp->memory_map)

This way, we avoid Transaction Lookaside buffer flushing if
only switching to another *thread* inside the actual *process* *gg* I'm not nitpicking am I? ];->

Re:Multitasking???

Posted: Fri Oct 15, 2004 7:23 am
by Solar
It all depends on what you want to do, and the CPU you're running on... take note that on some CPUs the MMU holds more than one memory map in cache... ;)