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

Jack Jansen jack at piring.cwi.nl
Tue Aug 8 18:53:14 AEST 1989


In article <5568 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
>[ gaf at uucs1.UUCP (gaf) wants an n-way wait() ]
>
>In article <8311 at boring.cwi.nl>, guido at piring.cwi.nl (Guido van Rossum) writes:
>> Sounds like you need multiple threads in a single address space, or
>> light-weight threads as they are referred to in a discussion of the
>> subject in neighboring newsgroups.  I agree that they are *very* nice to
>> have in an OS.
>
>An n-way wait can be implemented by using N threads, having each of them
>waiting on a seperate event, and having a thread signal the mainline
>when its event occurs. It can also be implemented using software interrupts...
>(or in UNIX terms, signals). It's usually desirable, though, to implement
>an n-way wait anyway, because it may be more efficient.


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.

Usually, my select code looks like

    while(1) {
	select()
	if( event-1 ) {
	    handle-event-1;
	}
	if( event-2 ) {
	    handle-event-2;
	}
	etc;
    }
With multiple threads, you would have multiple threads each doing
a simple
	while(1) {
	    wait();
	    do-event;
	}
Not only do I find this much easier to understand, but there are also
other advantages, like having local state on the stack in stead of
having a global array that you have to index by event number each time
(think of things like handling two or more keyboards at the same
time).
-- 
--
Een volk dat voor tirannen zwicht	| Oral:     Jack Jansen
zal meer dan lijf en goed verliezen	| Internet: jack at cwi.nl
dan dooft het licht			| Uucp:     mcvax!jack



More information about the Comp.unix.wizards mailing list