🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #5420

Re: threads in user mode (was Modula to Oberon)

#5420
From: der Mouse
Date: Tue, 12 Apr 1988 08:37
38 lines
2298 bytes
In article <269@cantuar.UUCP>, james@cantuar.UUCP (J. Collier) writes:
> Peter da Silva (peter@sugar.UUCP) writes:
>> I'd like to see the following functions become standard in 'C':
>> ....
>> COROUTINE -- Build a jmp_buf for a coroutine.
> Correct me if I'm wrong, but I find that on some machines (well, on
> BSD Vaxen anyway) setjmp()/longjmp() can't be used to implement
> coroutines because longjmp() unwinds the stack destructively while
> checking for botches.  A small amount of in-line assembly language is
> therefore necessary for transferring control.

It doesn't *have* to be inline.  Certainly not on a VAX, and probably
not on other machines.

> Pre-empting threads which share a common data space are probably not
> a good idea for most purposes - the synchronisation problems usually
> outweigh any advantages.  [...]  Threads with explicit sleep() calls
> and round-robin transfer [...] are one way of organising things.

I once wrote a hack which used SIGALRM to switch among several threads
running in the same data space (with different stacks, of course).
This was under 4.3BSD on a VAX.  It required a little assembly assist
(about forty lines) and depended on knowing the details of the signal
delivery mechanism.

But it allows any of the above.  Use setitimer() to request periodic
SIGALRMs and your scheduler code can implement pre-emption, or you can
use kill() to send SIGALRM to yourself and use this to build an
explicit sleep routine.

I never developed it; it's a solution in search of a problem at the
moment (it was written more as proof-of-concept than anything else).
If anyone wants it, to use or read, feel free to send me mail.

					der Mouse

			uucp: mouse@mcgill-vision.uucp
			arpa: mouse@larry.mcrcim.mcgill.edu
Technical Details
Message-ID: <1044@mcgill-vision.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mcgill-vision!mouse
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <3764@bloom-beacon.MIT.EDU> <269@cantuar.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mcgill-vision!mouse
From: mouse@mcgill-vision.UUCP (der Mouse)
Newsgroups: comp.lang.misc,comp.unix.wizards,comp.lang.c
Subject: Re: threads in user mode (was Modula to Oberon)
Message-ID: <1044@mcgill-vision.UUCP>
Date: 12 Apr 88 08:37:21 GMT
References: <2827@enea.se> <1557@pasteur.Berkeley.Edu> <3764@bloom-beacon.MIT.EDU> <269@cantuar.UUCP>
Organization: McGill University, Montreal
Lines: 37