Re^2: What kinds of things would you want in the GNU OS?

Peter da Silva peter at ficc.uu.net
Wed Aug 9 03:55:23 AEST 1989


In article <8318 at boring.cwi.nl>, jack at piring.cwi.nl (Jack Jansen) writes:
> Well, I've noticed that it is actually the other way around: everytime
> I use select() I really wanted multiple threads in the first place
> and only used select because they weren't there.

If you have select you can implement n-way threads trivially, subject to
language considerations. In Forth it was a matter of some 40 lines of
code to get the co-routines working. In C, well, I would expect the
context-switch and stack-allocation stuff would be non-portable. What
I'd really like to see in a future C library standard would be a portable
implementation of:

	typedef struct {
		int initial_stack_size;
		void (*initial_pc)();
		...
	} context_template;

	context = create_context(context_template);
	status = destroy_context(context);
	switch_context(context);

Plus some sort of co-ordination (semaphores, monitors, messages, or
whatever). Multitasking, coroutines, whatever... could be built on
top of this. Because the context switch is implicit you don't get to
deal with race conditions (such as switching context inside of malloc).
You still have to worry about globals, though.

> With multiple threads, you would have multiple threads each doing
> a simple
> 	while(1) {
> 	    wait();
> 	    do-event;
> 	}

Co-ordination then becomes a problem. I've worked with both programming
models on the Amiga, where they're supported, and each has its place. It's
a LOT easier to debug the simple-event-loop, but if it gets too complex
you can always go the other way.
-- 
Peter da Silva, Xenix Support, Ferranti International Controls Corporation.
Business: peter at ficc.uu.net, +1 713 274 5180. | "The sentence I am now
Personal: peter at sugar.hackercorp.com.   `-_-' |  writing is the sentence
Quote: Have you hugged your wolf today?  'U`  |  you are now reading"



More information about the Comp.unix.wizards mailing list