Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.unix.wizards Subject: Re: What kinds of things would you want in the GNU OS? Message-ID: <4365@ficc.uu.net> Date: 31 May 89 19:30:11 GMT References: <106326@sun.Eng.Sun.COM> <31756@bu-cs.BU.EDU> <8565@chinet.chi.il.us> <16603@rpp386.Dallas.TX.US> Organization: Xenix Support Lines: 39 In article <16603@rpp386.Dallas.TX.US>, jfh@rpp386.Dallas.TX.US (John F. Haugh II) writes: > In article <4347@ficc.uu.net> peter@ficc.uu.net (Peter da Silva) writes: > >An efficient version of threads would not even duplicate the stack area... > As you unwind stack frames in either thread, you would reach a point > where you start trashing the stack frames of the either thread. This assumes you can unwind the stack. You're assuming that the thread() call looks like fork(). That's not efficient. You need something like: pid = thread(initial_PC, final_PC, initial_stack_size, maximum_stack_size, priority); Used like so: void do_raytrace(); void cleanup(); int trace_pid; trace_pid = thread(do_raytrace, cleanup, 256, 1024, 5); This creates a new stack for the thread (256 bytes if it's growable, 1024 bytes otherwise), pushes the address of 'cleanup' on it, and jumps to the start routine: do_raytrace(). Cleanup looks like this: cleanup() { thread_exit(); } This avoids duplicating (or potentially duplicating) a large amount of data, and avoids having to swap MMU contexts for the new stack when you enter the thread. The entire MMU context of the parent and child threads can be the same. -- Peter da Silva, Xenix Support, Ferranti International Controls Corporation. Business: uunet.uu.net!ficc!peter, peter@ficc.uu.net, +1 713 274 5180. Personal: ...!texbell!sugar!peter, peter@sugar.hackercorp.com.