In this homework you will write a user-space thread system (named “qthreads”, vs. the standard “pthreads” library), which creates threads, performs context switches, and includes implementations of mutexes and condition variables. You will use your code in two applications – your own test procedures, and a simple threaded webserver provided as part of the example.
Programming Assignment materials and resources You will download the skeleton code for the assignment from the CCIS repository server, github.ccs.neu.edu, using the 'git clone' command:
You should copy this code to a subdirectory in your github team repository under hw1. For example if you are on team 1
git clone git@github.ccs.neu.edu/cs5600-03-sp2018/team-1 cd team-1 mkdir hw1 cp -a /path/to/hw1/* hw1 So that your team repository looks like
ls team-1
hw1
Homework 1 – User-space threads Page 2 of 3
You should be able to complete this homework on any x86 Linux system however
Repository Contents The repository you clone contains the following files:
qthread.c, qthread.h – these are the files you will be implementing. They have some comments in them describing the functions and types you have to implement.
switch.s, stack.c – these contains the context switch function (switch_from_to) and the stack initialization function (init_stack). You should not change these files. The functions are more complex than the the ones discussed in class because they contain protection code designed to abort into the debugger if you try to switch to an invalid stack.
test1.c – this is where your test code should go. (well, you can add additional files and update the makefile if you do) server.c – a simple multi-threaded webserver using qthreads.
Makefile – this is set up to build executables for ‘test1’ and ‘server’. Compile your code by typing ‘make’.
Deliverables The following files from your repository will be examined, tested, and graded:
qthread.c, qthread.h test1.c
Page 3 of 3
Qthreads interface First, two function pointer typedefs – one for a function taking two arguments (with no return value) and the other taking one argument and returning ‘void*’. These will make the following definitions easier to read.
You will need to implement the following functions – first, the basic functions to start and exit a thread, run the thread scheduler, and wait for a thread to finish (“join”).