CSCI 152: Operating Systems Programming
Laboratory Assignment 3
Assignment Description:
Lab 3 involves adding a modification to lab 2. So as long as you
completed lab 2 and lab 1 it should not be too difficult.
In lab 2 each "producer" was a thread created by main() and generated
print jobs in a somewhat random fashion. In lab 3 this portion of
the program will be modified so that main() creates a network server
and each client that connects to the server is a "producer". So a
client can connect and generate print jobs interactively.
Each network server thread does the following:
- loops until client sends a quit string like "Q" (or until error,
depending how you do error handling).
- receives a command of the form "jobID pages"
- for example "2222 9" means job ID 2222 is 9 pages long
- see if there is room in the queue by doing a sem_wait()
- when there is room in the queue then lock the queue using a
mutex
- add a print job to the queue
- remove the lock on the queue
- exits when a quit command is recieved
Create producer ID's in some fashion. (Maybe use a
incrementing counter or by choosing a random integer or the thread_id,
etc.) Each producer should have a unique ID so that the server
can send output to the terminal like "Printer 5 printing Job 12 page 1
of 3 from Client 4".
Please note in Lab 1 most students implemented a network
server capable of handling multiple clients simulaneously by using the
system call fork(). In this lab you must accomplish the same
thing except by using POSIX threads.
Consumer threads are created the same way as they were in Lab 3.
Problems to Avoid in Producer/Consumer:
- A consumer removes an item while a producer is in the process of
putting it in the queue.
- A consumer removes items that are not there at all.
- A consumer removes items that have already been removed.
- A producer puts something in the queue when there is no free slot.
- A producer overwrites an item that has not been removed.
Goals:
Learn about operating system fundamentals, including history, process
and thread
management, concurrency with semaphores and monitors, deadlocks,
storage management, file systems, I/O, and distributed systems.
Objectives:
- Learn about sychronization issues involved in solving a
producer-consumer problem.
- Learn about the use of threads.
- Learn about the use of semaphores (waiting).
- Learn about the use of mutexes (locking).
- Learn about the use of sockets and network programming.
Expected Outcome:
- This project must be completed in groups of 1 to 3 people.
- This project must be completed using one of the following
languages
- The platform you do this project on must support posix threads,
semaphores, and mutexes.
- Completing this assignment on tiglon
is recommended for most students.
- Any platform is okay as long as that platform supports posix
threads, semaphores, and mutexes.
- Lab 2 a prerequisite to completing this lab.
- Except for changes explicitly stated in the description all
requirements for lab 2 are also required for lab 3.
- see the grading sheet
- The server must be capable of handling multiple clients
simultaneously.
- Some Changes from lab 2
- Neither main() or Consumer threads (printers) ever exit.
- The server only needs to exit by <CTRL>-C
- Feel free to implement some other way to exit the server although the "server" is a server and should not exit automatically.
- Using strictly C is not a requirement for this program, C++ can
be used also.
- Note that Telnet Clients do not need to print any messages from the server.
- They only need to be able to send messages.
- You can improve on this of course.
- Documentation is required
- TURN-IN
- print out of all code used to create
this project.
- print out COVER SHEET
- you must demonstrate this
project to your TA during lab.
- you must turn-in an evaluation of yourself
and your group members.