threads in user mode (was Modula to Oberon)
der Mouse
mouse at mcgill-vision.UUCP
Tue Apr 12 18:37:21 AEST 1988
In article <269 at cantuar.UUCP>, james at cantuar.UUCP (J. Collier) writes:
> Peter da Silva (peter at 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 at mcgill-vision.uucp
arpa: mouse at larry.mcrcim.mcgill.edu
More information about the Comp.unix.wizards
mailing list