Re: Threads question

Tom Dailey (
Sat, 26 Apr 1997 11:41:49 -0700

Alan Cox wrote:
> > Threading is good, use the kernel facilities, and don't over do it.
> > People who think they need thousands of threads really don't, they
> > just need to heavily rethink their design.
> One problem is that the entire world needs to go back to early 1970's
> or previous and look up the world CO-ROUTINE. The coroutine scheme doesn't
> do parallel execution but is a nice very small and very clean way to express
> a lot of the things people misuse threads for. Threads have their place
> in parallel execution. They do not have a place as shortcuts to context
> and state management issues.
> Alan

You make an excellent point. In fact, user-level threads packages are
usually just n-ary coroutine managers in disguise. Thus, when a user-
level thread blocks, it is simply making a coroutine transfer to another
(suspended) user-level thread, via some scheduling mechanism that is
entirely under the user's control. One downside to this is that such
threads managers are nonpreemptive, and so part of the threads
scheduling policy may have to be embedded in the code executed by the
threads, in the form of thread_yield (or whatever) calls, to prevent
that code from hogging the CPU. The other downside, of course, is that
(pure) user-level threads cannot take advantage of multiple CPUs.

Tom Dailey