CBThread - Continuation-Based Thread Library

James S. Plank

EECS Department
University of Tennessee
Knoxville, TN 37996


The Continuation-Based Thread library (cbthread) is a simple and slightly bizarre library that implements continuation-based, non-preemptive threads. They are extremely useful when you need a lightweight, non-preemptive and portable thread library.

The continuation-based paradigm means that no potentially blocking thread call will return to the caller. Instead, such calls take a continuation, which is a function and parameter, as arguments. When a potentially blocking call unblocks, the continuation is invoked. While this is a little weird, it means that threads do not need to have their own stacks, as they do in standard thread libraries like pthreads. As such, each thread only consumes a few bytes of memory, allowing you to have millions of threads without running out of memory as you do when threads have their own stacks. This is very nice.

A downside of having a non-preemptive thread system is that you cannot assign threads to blocking system calls as you can with pthreads, and have threads run while the system call blocks. If you do, the entire process blocks. Regardless, I have found that cbthreads are exceptionally useful for many programming tasks.

Home, Source Files, Compiling and Linking

The home for cbthreads is http://www.cs.utk.edu/~plank/plank/cbthread.

The cbthread library is composed of one source file (cbthread.c) and one header file (cbthread.h). You will also need to compile with the Libfdr library, available at: http://www.cs.utk.edu/~plank/plank/classes/cs360/360/notes/Libfdr/.

Learning to use cbthreads

I have not written up a manual for the cbthread library. Instead, I have a sequence of three lectures that allow you to learn all about them:

The third lecture is not required to use the library -- it is just there to understand the implementation. If you use CBThreads If you use cbthreads in your work/research/development, please send me an email (plank@cs.utk.edu) letting me know. My department, university and funding agencies like to know of the impact of my work, and documenting usage is one way to do this.

Acknowledgements

This material is based upon work supported by the National Science Foundation under grant CNS-0615221.