DOC PREVIEW
UConn CSE 2102 - Lab 9

Previewing page 1

Save
Premium Document
Do you want full access? Go Premium and unlock all 1 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE 3100 Systems Programming Fall 2018Lab #9Welcome to Lab 9! This lab assignment is due by the end of Tuesday, Nov. 27, 2018.Read the question carefully before beginning to work. Start by executing git pull inside your Gitrepository on the virtual machine. Remember to add, commit, and push when you complete your work.Add ONLY *.c to the git repo. Do not add .o files or executables.Computers & printers (100 Points).Suppose c computers work together to get j print jobs done with p printers. A queue of size q buffersthe print jobs between computers and printers. You can see this is a system with multiple producers andmultiple consumers. In this assignment you need to simulate the operation of the computers and printersusing threads.Each computer thread generates new print jobs by calling the work() macro and submits them to thequeue using q submit job(). If the queue is full, i.e., there are already q jobs pending, the computer threadmust wait. After a job is added to the queue, the computer thread continues to prepare and submit printjob until a total of j jobs have been collectively submitted by the c computer threads. It is OK if a printjob is prepared but not submitted because the maximum has been reached.If there is any print job pending, a printer thread fetches the first job from the queue using q fetch job()and prints it by calling the print job() macro. This macro simulates the fact that different print jobs takedifferent amounts of time to complete. If the queue is empty, a printer thread trying to fetch a new job mustwait until a job becomes available.The code for queue operations is already provided in computer-printer.c. Your code only needs tocall the provided functions to operate on the queue. The file tasks.c gives C code implementing the basicfunctionality of the computer and printer threads but is lacking any code for ensuring mutual exclusion andsynchronization between threads.Complete the code in computer-printer.c to simulate the process of printing j jobs with a queue ofsize q, using one mutex and two condition variables. The program should allow as much parallelism betweencomputers and printers as possible. The values of c, p, j, and q can be specified as command arguments.Read the code for the default values. Note that a large number of computers results in eager producers anda large number of printers lead to eager consumers.A script check.py is provided to do some basic checks on the output of computer-printer. Below is anexample of how to to use check.py.$./computer-printer -c 20 -p 5 -q 8 -j 100 | ./check.pyNote that it is not guaranteed that a program that passes the check is correct. Some synchronizationerrors may manifest themselves only for some values of the parameters, and even for the same parameterserrors may happen non-deterministically due to different timing and scheduling orders of the threads on thevirtual machine.With multiple threads is also possible to reach a deadlock, i.e., a situation where threads wait on eachother without making any more progress. One way to diagnose the problem in this case is to use themultithreading features of gdb. You can run your code in gdb until it appears to stop making progress (forthis lab, the threads will stop printing messages to the standard output). Then• Interrupt the execution of the program with Ctrl-C to get the gdb prompt• See what threads are running using the “info threads” command of gdb• If needed, switch between the threads by using “thread N”, and use other gdb commands to see whatthe threads are executing, inspect values of local variables,


View Full Document

UConn CSE 2102 - Lab 9

Documents in this Course
Load more
Download Lab 9
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab 9 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab 9 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?