[comp.lang.c] threads for C/C++ under Unix: SUMMARY

hall@polya.Stanford.EDU (Keith A. Hall) (10/22/89)

I enquired about the existence of a portable preemptive thread package
for Unix.  I received information about six such packages:

  Brown Threads (Brown Univ)
  Portable Common Runtime (Xerox PARC)
  C Threads for Unix (CMU)
  Presto (U of Washington)
  uSystem (U of Waterloo)
  ConcurrenC (Purdue Univ?)

Below are the responses I received and persons to contact if you want
additional information.

Many thanks to Tom Doeppner, Mark Weiser, Eric Cooper, David Keppel,
Peter Buhr, Don Libes, and others.

Regards,
Keith Hall
hall@eclipse.stanford.edu

================

*** BROWN THREADS ***
contact Tom Doeppner (twd@cs.brown.edu)

I have written a threads package that may be what you want.  It's known as
"Brown threads" and runs on VAXes, sun-3's, sun-4's, Mips (i.e. decstation
3100), and Encore Multimaxes.  Threads may independently do I/O system calls,
and there is a thread-safe version of stdio and malloc/free.  The package is
available from Brown either through anonymous ftp or by mail (for a nominal
charge).  No license is required except for the stdio package which is
derived from 4.3-tahoe stdio, which was derived from an AT&T product.

The package requires no kernel mods.  Kernel mods would be nice at
several points.  The scheduler in the threads package has to make too
many system calls to protect it from threads to mention one problem.
I/O may not behave exactly as you would like.  Multiple threads may
read from the same file descriptor, but the programmer is responsible
to make sure that they read data consistent with any protocol being
implemented.

For mutual exclusion, there are binary and counting semaphores and monitors.
The monitors would be more useful with the fromt end since they require
the entry and exit calls to be placed by hand.  There is even an interface
that is almost source compatible with Mach Threads.

Threads may be obtained via anonymous ftp from wilma.cs.brown.edu in
the "pub" directory.  Since the modified stdio library requires a UNIX
source license, we can't make this available to everyone.  The file
threads.tar.nostdio.Z contains the freely distributable version of
threads.  The file threads.tar.Z contains the stdio library as well,
but is currently read-protected.  If anyone wants that version, they
need to contact me and provide evidence that they have a source
license.

========

*** PORTABLE COMMON RUNTIME ***
contact Mark Weiser (mark@arisia.xerox.com)

We have a package that does what you want, more-or-less, except for
the protected standard C library (which is not an OS issue in any
case).

There is a paper 'to appear' in December '89 at SOSP, entitled "The
Portable Common Runtime Approach to Interability" which will describe
our package.

========

*** C THREADS FOR UNIX ***
contact Eric Cooper (eric.cooper@cs.cmu.edu)

There is a non-preemptive version of C Threads that works on vanilla
UNIX.  It is being extended for the undergraduate operating system
class this term to use simple preemption based on the UNIX alarm
signal.  Note that none of this is "portable"; the context switch and
mutual exclusion must be written in assembler for each machine. This
has been done for half a dozen CPU types already, and takes only a day
or two.

I've placed the nonpreemptive version in the public domain, and will
do the same for the preemptive version as soon as it's stable.  The C
Threads header file is usable as-is with C++.

Note that the current version has no support for preemption.  In
particular, you can't use UNIX interrupt handlers with it and expect
it to work correctly (since there's no locking or masking of
interrupts around critical sections).  There's a simple-minded
workaround for the select() system call to allow threads to do I/O
operations without blocking the entire UNIX process.

========

*** PRESTO ***
contact sandstro@opus.cs.washington.edu
     or David Keppel (pardo@june.cs.washington.edu)

There is a multiprocessor threads package called `Presto' that was
written locally.  It combines C++ and some local libraries to create a
`vaguely' portable preemptive-scheduled thread package.  Sources are
available via anonymous ftp from june.cs.washington.edu (128.95.1.4)
in pub/presto0.4.tar.Z.  It runs on the Sequent Symmetry and Balance,
and some uniprocessors.  No OS modifications are needed.

Presto is described in U of W tech report 78-09-01, "Presto: A System
For Object-Oriented Parallel Programming".

Generally, a `portable' threads package requires a small ammount of
(machine- and compiler-dependent) assembly, and depends also on the
signal mechanism.  The total ammount of code that needs to be written
for a new port is 30 lines of assembly (your milage may vary) plus any
signal handler wierdness (not much on standard boxes).

========

*** USYSTEM ***
contact Peter Buhr (pabuhr@watmsg.waterloo.edu)

This is an abstract of the uSystem.  If it interests you, you may get
the complete uSystem reference manual by anonymous ftp from:

  watmsg.waterloo.edu (129.97.129.9) in /u/ftp/pub/uSystem/uSystem.dvi

The uSystem is a library of C routines that provide concurrency on
uniprocessor and multiprocessor hardware running the UNIX operating system.
Concurrent operations in the uSystem are explicitly specified and not
inferred from existing constructs in C.  Users first design algorithms that
are inherently concurrent and then explicitly code corresponding concurrent
operations using the routines in the uSystem.

The uSystem uses a shared-memory model of concurrency.  This shared-memory
is populated by subroutines, coroutines and concurrently executing
light-weight processes, called tasks.  Coroutine mechanisms are provided to
create coroutines within a task and to communicate information among the
coroutines.  Concurrency mechanisms are provided to create tasks within the
shared memory, to synchronize execution of the tasks, and to communicate
information between synchronized tasks.  Task execution is uniformly
distributed across UNIX processes which are used as virtual processors.  A
mechanism exists to group virtual processors into a cluster and restrict
task execution to only these virtual processors, but it is not encouraged
except in special situations as it restricts the potential for concurrency.
Support is also provided to use UNIX I/O facilities concurrently.

The uSystem does not enter the UNIX kernel to perform a coroutine or task
switch and uses shared memory among tasks.  As a result, performance for
execution and communication between large numbers of tasks is significantly
increased over UNIX processes (e.g. two orders of magnitude in some cases).
The maximum number of tasks that can be active is restricted only by the
amount of memory available in a program (e.g. we have test programs that
create over 20,000 tasks).

========

*** CONCURRENC ***
contact: xinu-info-request@cs.purdue.edu

ConcurrenC is preemptive thread package for UNIX based on Xinu.  It is
not entirely portable, but it is as close as possible.

Here is the relevant stuff from a posting by Ken Rodemann in comp.os.xinu:

   ...Unix C library routines are made mutual exclusive, and a
   blocking I/O ConcurrenC task does not block other tasks in the
   system.  The ConcurrenC system includes src for the Xinu/ConcurrenC
   routines, source for modified Unix C library routines, and manual
   pages which list the Xinu name changes within ConcurrenC,
   restricted Unix system calls, etc.

I suggest you read/write the xinu-info@purdue.edu mailing list for
more info on ConcurrenC.