Path: utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!cs.utexas.edu!sun-barr!texsun!texbell!uhnix1!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.unix.wizards Subject: Re: Re^2: What kinds of things would you want in the GNU OS? Message-ID: <5601@ficc.uu.net> Date: 8 Aug 89 17:55:23 GMT References: <160@uucs1.UUCP> <8311@boring.cwi.nl> <5568@ficc.uu.net> <8318@boring.cwi.nl> Organization: Xenix Support, FICC Lines: 44 In article <8318@boring.cwi.nl>, jack@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@ficc.uu.net, +1 713 274 5180. | "The sentence I am now Personal: peter@sugar.hackercorp.com. `-_-' | writing is the sentence Quote: Have you hugged your wolf today? 'U` | you are now reading"