What kinds of things would you want in the GNU OS? (really threads)

Guido van Rossum guido at piring.cwi.nl
Wed Aug 9 22:16:00 AEST 1989


peter at 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 at cwi.nl or mcvax!guido or guido%cwi.nl at uunet.uu.net
"Repo man has all night, every night."



More information about the Comp.unix.wizards mailing list