9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] cooperative threads
@ 2000-08-18 22:06 Russ Cox
  2000-08-18 22:56 ` Boyd Roberts
  2000-08-19  6:34 ` Lucio De Re
  0 siblings, 2 replies; 5+ messages in thread
From: Russ Cox @ 2000-08-18 22:06 UTC (permalink / raw)
  To: 9fans

A more important point is that coroutines,
or cooperative or non-preemptive threads,
or whatever you want to call them, have their
benefits.

As demonstrated by early versions of Windows
and the Macintosh OS, reliance on cooperative
threading alone is a recipe for disaster, since 
it requires that all threads be bug free.  Thus,
used as an OS's primary scheduling mechanism,
cooperative threading requires that all executing
programs be bug free, a very strong and very
unlikely condition.  In that arena, cooperative
threading is not the right framework.

In more controlled settings, cooperative 
threading can work well.  If you arrange things
so that the only accesses to a data structure
are from threads inside a single proc, you
don't need to lock the data structure as long
you don't do a potentally blocking operation
(like communication) while manipulating it.
This is just one small benefit.  Structuring 
using coroutines can simplify other aspects
as well.  See, for instance, the ``Concurrency
in the Implementation'' section of the Acme
paper, any of the three references listed in
that section, and www.cs.dartmouth.edu/~doug/squint.ps.gz.

One of my gripes about the software-writing
world is that too many people hear threads
and think of performance alone.  A friend of
mine was taking a networks class and was
barred from using threads to simplify his
program structure.  The justification given
was that on the OS in question the thread 
package did not involve the kernel, so there
were no performance wins to be gained.
Thus using threads had no point.

My intent is not to get into an argument over what
the ``right'' scheduling model is, since it depends
greatly on the task at hand.  Instead I simply
wish to point out that cooperative threads do
have their uses and merit a place as a single tool
in a larger toolbox.

Russ



^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [9fans] cooperative threads
@ 2000-08-21 13:01 rob pike
  0 siblings, 0 replies; 5+ messages in thread
From: rob pike @ 2000-08-21 13:01 UTC (permalink / raw)
  To: 9fans

> I think threads are popular for two main reasons:
> (1) They are an easy way to exploit multiple processing units.
> (2) They are much lighter weight than communicating full processes.

1) is irrelevant on a uniprocessor while 2) is a red herring: processes
are not intrinsically heavyweight.  Nonetheless, I agree that these
are the reasons threads are popular.

However, they are used throughout Plan 9 for a different reason:
they provide an excellent approach for structuring programs,
especially programs that must handle multiple sources of input.
Examples include user-level file servers and anything interactive.
See
	http://plan9.bell-labs.com/cm/cs/doc/89/1-a.ps.gz
for some old thinking of mine on the subject.  This paper was
written a couple of years before 8½, but you can see where I'm
going.

-rob



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-08-21 13:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-18 22:06 [9fans] cooperative threads Russ Cox
2000-08-18 22:56 ` Boyd Roberts
2000-08-19  6:34 ` Lucio De Re
2000-08-21  8:59   ` Douglas A. Gwyn
2000-08-21 13:01 rob pike

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).