🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #5385

Re: Multi-thread on Ms-dos

#5385
From: Jeff Pipkins Dev hou
Date: Fri, 22 Mar 1991 15:55
54 lines
3091 bytes
In article <104499@unix.cis.pitt.edu> bill@hpb.cis.pitt.edu (Bill Broadly) writes:
>
>	I need a small C program that allows running more that
>one thread, using setjmp, and longjmp, on a ms-dos machine.  Nothing 
>pre-emptive needed.  
>	Exactly what I wanted was in the Jan issue of C users Journal,
>but I couldn't get it to work, and the author is in England (no Email
>address).
>	Anybody out there have such a beast?  Or get the one from the
>magazine to work?  
>	I don't want anything so involved as Ctask.  I don't need real
>multitasking just the ability for one process to say "I done for now,
>next process can run".
>	I will happily mail the code to anyone if they want the
>original (non-working) code from the article.
>	I have (bought) MSC 6.0 (with revision), MSC 5.1, TC++.
>			-Bill
>			Broadley@schneider3.lrdc.pitt.edu
>
>-- 
>Bill Broadley
>Broadley@schneider3.lrdc.pitt.edu
>			"GISMO"

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.

Good idea, but it just doesn't work...

-- 
Jeff D. Pipkins  (pipkinsj@cpqhou.se.hou.COM  or  uunet!cpqhou!pipkinsj)

Disclaimer: My opinions do not necessarily reflect those of my employer.
"Things should be made as simple as possible, but no simpler" --Einstein
Technical Details
Message-ID: <1991Mar22.155529.22@cpqhou.uucp>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cpqhou!pipkinsj
References: <CHAS.91Mar15142516@stax.uchicago.edu> <104499@unix.cis.pitt.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!cpqhou!pipkinsj
From: pipkinsj@cpqhou.uucp (Jeff Pipkins @Adv Dev@SE hou )
Newsgroups: comp.os.msdos.programmer
Subject: Re: Multi-thread on Ms-dos
Message-ID: <1991Mar22.155529.22@cpqhou.uucp>
Date: 22 Mar 91 15:55:29 GMT
References: <CHAS.91Mar15142516@stax.uchicago.edu> <104499@unix.cis.pitt.edu>
Reply-To: pipkinsj@cpqhou.UUCP (Jeff Pipkins @Adv Dev@SE hou )
Distribution: comp.sys.ibm.pc.programmer,comp.sys.ibm.pc.misc
Organization: Compaq Computer Corporation
Lines: 54