delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/10/16:57:03

From: "Alexei A. Frounze" <alex DOT fru AT mtu-net DOT ru>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Processor Exceptions
Date: Mon, 10 Apr 2000 23:25:58 +0400
Organization: MTU-Intel ISP
Lines: 37
Message-ID: <38F22AC6.ECCC858D@mtu-net.ru>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1000410203520 DOT 26090G-100000 AT is>
NNTP-Posting-Host: ppp102-126.dialup.mtu-net.ru
Mime-Version: 1.0
X-Trace: gavrilo.mtu.ru 955395487 73052 212.188.102.126 (10 Apr 2000 19:38:07 GMT)
X-Complaints-To: usenet-abuse AT mtu DOT ru
NNTP-Posting-Date: 10 Apr 2000 19:38:07 GMT
X-Mailer: Mozilla 4.61 [en] (Win95; I)
X-Accept-Language: en,ru
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Let me explain...

1. You prepare N separate tasks/threads by allocating separate stack for each
task/thread.

2. You push initial values of (E)FLAGS, CS:(E)IP and other registers to their
stacks.

3. You load SS:(E)SP with one of those stacks. Pop registers back and perform an
IRET(D). Hence you do 1st task/thread switching.

4. When becoms time of another task switch (timer IRQ is generated), you push
the rest of the registers (except of (E)FLAGS and CS:(E)IP, since they are
already on stack). Then you load another SS:(E)SP pair, pop regs and perform
IRET(D) once more. Thus you get 2nd,3rd,... Nth task switch.

I hope you understand the basic idea.

The example program I mentioned also gives diffeernt periods of time. I.e. some
kind of advanced multitasking/multithreading.

Good Luck
Alexei A. Frounze
-----------------------------------------
Homepage: http://alexfru.chat.ru
Mirror:   http://members.xoom.com/alexfru

Eli Zaretskii wrote:
> 
> On Mon, 10 Apr 2000, Alexei A. Frounze wrote:
> 
> > Why not to use the stack switch trick for the multithreading instead of real
> > exceptions?
> 
> Sorry, I don't understand: what ``stack switch trick''?


- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019