next up previous
Next: Message passing using Copy-on-Write Up: Problem Statements Previous: Problem Statements

Implement a pre-emptive user level thread library

You need to implement the following functions in the thread library

To implement a user space thread library, you need to implement a scheduler, which can be a simple round robin scheduler. Start with a simple non pre-emptive thread library where you reschedule only when the thread calls uthread_yield or exits.

The first step can be implemented either by using the setjmp/longjmp combination or using getcontext, makecontext, setcontext, swapcontext. You must read the man pages of all the functions mentioned above. The functionality of the functions in your thread library are the same as the pthread library. You must check the corresponding man pages(man pthread_XXX).

The thread library must be made pre-emptive. That is, the threads can be pre-empted to reschedule when they are executing the application code. Note that the threads that are executing library code and the scheduler functions cannot be pre-empted. You need to protect the functions of the library(Hint: Flag access to the library).

For pre-emption, you need to set up a high resolution timer and handle the signal to reschedule. One such timer is accesible through setitimer.

To use pre-emptible threads, you must have some synchronisation primitives. These allow effective and safe sharing of data. In your user level thread library, you must have a set of mutual exclusion and conditional variable primitives implemented. Some of the primitives that you need to implement are

You must familiarize yourself with the exact semantics of the above functions before implementing them. Notably the cond_xxx have strange semantics.

Your makefile must create libuthreads.a which can be linked with any application to use your user level threads.


next up previous
Next: Message passing using Copy-on-Write Up: Problem Statements Previous: Problem Statements
Aniruddha Bohra 2001-10-08