T-Threads, a Lightweight Thread Package
Design
Thread API Examples
Source
Code
Design:
Threads are units of concurrent execution. T-Threads
is a C++ object oriented thread-package where threads and synchronization
primitives are objects with operations to initialize,
run, and block . We have built the the thread package with three
main design goals: performance, portability, and extensibility.
Performance
A thread package can either be implemented as a pure
user-level thread package, a kernel-level thread package or a hybrid-implementation
that takes advantage of both schemes. A strictly user-level thread package
has the disadvantage that they cannot make use of
multiple processors in a box. Kernel-level threads can take dvantage of
parallelism but it is very inefficient because it
requires communication with the O.S. Kernel through system calls. For example,
each creation of a thread requires a system call.
In a hybrid scheme, we initially create a kernel-level thread per CPU.
These kernel-threads, called workers, then create
and schedule user-level threads which may move from one worker to another
to balance the load by using work queues. This hybrid
scheme, sometimes known as a two-level scheduling implementation, has the
best of both worlds: like user-level threads they
incur little overhead and like kernel-level threads, we can make use of
multiple CPU's.
Another way in which T-Threads improve performance is
by taking advantage of any hardware provisions provided by a
particular architecture.
A comparison of T-Threads with other thread packages can
be found here.
Portability
T-threads library has been ported to many architectures
and operating systems, including i386/i486/pentium
processors running Linux, DEC Alpha running OSF/1. SPARC stations
running Solaris, and R8000/R10000 running SGI IRIX and it is currently
being ported to IBM/SP2.
Extensibility
In T-Threads, threads and primitives required
in thread library such as mutexes and barriers are C++ objects
that can be specialized by users to suit their purposes. By subclassing
the basic primitives provided by the package,
users can adapt the package for their needs.
Thread API: