Path: utzoo!utgpu!watmath!att!pacbell!ames!sun-barr!cs.utexas.edu!uunet!mcvax!piring.cwi.nl!guido From: guido@piring.cwi.nl (Guido van Rossum) Newsgroups: comp.unix.wizards Subject: Re: What kinds of things would you want in the GNU OS? (really threads) Message-ID: <8325@boring.cwi.nl> Date: 9 Aug 89 12:16:00 GMT References: <160@uucs1.UUCP> <8311@boring.cwi.nl> <5568@ficc.uu.net> <8318@boring.cwi.nl> <5601@ficc.uu.net> Sender: news@cwi.nl Lines: 42 peter@ficc.uu.net (Peter da Silva) writes: >[...] What >I'd really like to see in a future C library standard would be a portable >implementation of: > [...] > 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 ^^^^^^^^I assume you mean explicit >deal with race conditions (such as switching context inside of malloc). >You still have to worry about globals, though. A threads interface without synchronization primitives would be a farce. At the very least you need mutexes (binary semaphores). Other mechanisms (sleep/wakeup) are proven to be equivalent. A non-blocking mutex call (atomically test it and set it if not set) is a welcome addition. Timeouts are next (and really a generalization of the non-blocking call). A threads interface that assumes context switching is only done by explicit calls soon becomes a nightmare, because people tend to forget to use the mutexes when they "know" no other threads can execute in the mean time. This assumption is often invalidated by later additions to the code, by things that happen rarely deep inside routines you call, or by debugging options. But the real problem is that you really want to use the same threads paradigm on a true multiprocessor. Both problems are expemplified by the Unix kernel. Oh, on most hardware, mutexes can be made very cheap (a few instructions) in the common case that the mutex is free. I personally believe that you don't need primitives to kill threads or to wait for their completion; but this is really becoming a different thread of discussion. :-) -- Guido van Rossum, Centre for Mathematics and Computer Science (CWI), Amsterdam guido@cwi.nl or mcvax!guido or guido%cwi.nl@uunet.uu.net "Repo man has all night, every night."