User-level Threads

The goal of this programming problem is to implement a structured multitasking facility - `threads' - in Unix by multiplexing a single process. The facility and its implementation are similar to one described in `A micro-kernel for concurrency in C' (see below).

The header thread.h is an interface for the set of thread primitives described in the thread (3) man page. Programs that use threads can also use semaphores and channels for synchronization and communication. sem.h is the interface for the semaphore primitives described in the sem (3) man page, and chan.h is the interface for the CSP-style channel primitives described in the chan (3) man page.

Imlement the Thread and Sem interfaces on one of the SPARC, MIPS, ALPHA, or architecture of your choice. Implement all queues as first-in, first-out queues. You can call

extern void _swtch(void *from, void *to);

to switch context from thread from to thread to, where from and to are pointers to structures that begin with machine-dependent data, such as the stack pointer. Assembly language implementations of _swtch are available for the SPARC and the MIPS; use these as models for _swtch on other architectures.

An implementation of the Chan interface, which uses semaphores, is available in chan.c. Some test programs are available here.

References

D. R. Hanson, C Interfaces and Implementations: Techniques for Creating Reusable Software, Addison-Wesley, Menlo Park, CA, 1997. This book contains a solution to this assignement. You are not allowed to consult the book before the assignment due date.

G. V. Cormack, A micro-kernel for concurrency in C, Software - Practice and Experience 18, 5 (May 1988), 485-91.

C. A. R. Hoare, Communicating Sequential Processes, CACM 21, 8 (Aug. 1978), 666-77.

Submission

Turn in (by mail to b i l a s @ c s d . u o c . g r) a tar file that contains your solution and a README file stating assumptions or special features.


This material is courtesy of David R. Hanson
Copyright (c) 1995 by David R. Hanson