Due: November 10, 2008
Pthreads Examples
Read Chapters on threads and synchronization in the text. Also read the pthreads tutorial in the file pthreads-tutorial, which is one of the files in the tar archive pthreads.tar .
For each of the Phases below below, create a Makefile to compile and run test programs to show that your system calls are working properly.
Be sure to use "CFLAGS= -Wall -pedantic ..." in your Makefile. Address all warnings.
Make sure you follow all documentation standards indicated in class. ZERO credit for missing comments.
Be sure you have installed all man pages for program development!!! "man pthread_create" should work.
Read and add comments to the three pthreads examples in pthreads.tar .
Compile and run the examples
Be able to explain the examples.
Consider the examples here: (more will be in the next couple days).
EX1.tar . Untested code for a block server
that uses fork(), semiphores and shared memory to implement
the assignment below.
EX2.tar . closer code for a block server
EX3.tar . still closer code for a block server, see the README file.
Given a file "data" with 10 blocks of 16K bytes each, create a TCP server
that processes the following transactions:
SET <data 160K> // that sets the initial data, and can only be done
immediately after a CLEAR.
CLEAR // that removes the data file, READ/WRITE/SWAP are errors without
a valid data file.
READ <block number> // that returns the 16k in block <block number>
WRITE <block numnber> <data> // that writes a new block of 16K
in block <block number>
SWAP <block number 1> <block number 2> // swaps the blocks
Create a new thread to handle each incomming connection.
Wait 20 seconds before responding to each request.
Send an ACK after each operation completes including a sequence number.
Do not allow two copies of your server to be executed at the same time. Use a lockfile named /tmp/lock.as3 which contains the pid of the server.
Create client programs:
set <file name> // which sends the 160K file to the server
clear // which has the server "remove" the 160K data file
read <block number> <file> // which returns the block, putting it in the local <file>
write <block number> <file> // which sends the block in the local <file>
swap <block number 1> <block number 2> // which causes the blocks in the server to be swapped
You should add optional <port> and <domain name> arguements to your programs. Without the optional arguements assume the domain name is "localhost" and choose a non-privlaged port number.
Test your program carefully with scripts.
Check that there are no memory leaks.
Show that your server is really multitasking and not processing in a "sequential" manner.
Do a clean shutdown when:
An exit() call is made. See atexit()
A SIGINT siganl is recieved. See signal() and longjmp().
Show that your client and server work across a network.
start your server when the system boots up.
At the start of the server program, create a pool of threads, that will be used to process incomming connections.
Compare: the fork()/exec() solution from class, the solution from phase 2, and the solution from phase 4.
Does you solution depend on kernel level thread support?
Does you linux system provide kernel level threads or user level threads?
How could you use user level threads to still multithread this application?
Could you improve "performance" by using a memory catch for the data? What dioes "performance" mean here?