Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!maverick.ksu.ksu.edu!iowasp.physics.uiowa.edu!ns-mx!ccad.uiowa.edu!cadsi From: cadsi@ccad.uiowa.edu (CADSI) Newsgroups: comp.os.msdos.programmer Subject: Re: Multi-thread on Ms-dos Message-ID: <1991Mar23.051529.6868@ccad.uiowa.edu> Date: 23 Mar 91 05:15:29 GMT References: <1991Mar22.155529.22@cpqhou.uucp> Distribution: comp.sys.ibm.pc.programmer,comp.sys.ibm.pc.misc Organization: CAD-Research, U. of Iowa, Iowa City, Iowa Lines: 38 From article <1991Mar22.155529.22@cpqhou.uucp>, by pipkinsj@cpqhou.uucp (Jeff Pipkins @Adv Dev@SE hou ): > In article <104499@unix.cis.pitt.edu> bill@hpb.cis.pitt.edu (Bill Broadly) writes: >> > > This is a nice thought, but it doesn't work. I actually tried this scenario, > but the problem is that all threads have the same stack. As soon as any > one of them do a longjmp(), it throws away a piece of the stack. Then > the next thread writes over the values that were written there when it > uses the stack. When control gets back to the first thread, it can't > continue where it left off because much of its stack, containing local > variables, function arguments, and return addresses, is gone forever. > > There are certain very simple situations in which it seems to work, usually > in a program called test.c :) If you test this method in such a way > that the stack level is the same from one thread to another, then it will > work by happenstance. But if you use it for any real work at all, then > it will fail. Note that even if you try to design the threads so that > the stack levels are the same, that doesn't guarantee that it will work, > because the compiler may allocate different amounts of stack space for > each thread to use as temporaries in evaluating expressions. > > The fundamental truth here is this: you MUST have a separate stack for > each thread. There is no way around this. > > There is a way to do something similar to coroutines with setjmp/longjmp, > but it is rather delicate and unelegant. Actually, if you look through the back issues of Computer Language magazine, John Du Glosz (sp?) presented an article that did a similar procedure. He created stack arrays for each thread, and switched stacks as new threads came into scope. HOWEVER, he did not implement preemptive tasking, just Yield type calls. His algorithm is easily upgraded though. |----------------------------------------------------------------------------| |Tom Hite | The views expressed by me | |Manager, Product development | are mine, not necessarily | |CADSI (Computer Aided Design Software Inc. | the views of CADSI. | |----------------------------------------------------------------------------|