TWiki> CS361fall13 Web>Homework9 (revision 6)EditAttach

Synchronization using Semaphores

In this homework, we solve several synchronization problems using standard semaphores. The homework template, available at svn:// contains skeleton solutions, as well as a number of test-cases. A correct solution passes every test case. Plus, except where noted, your solution must have no loops: for, while, goto or recursive!

To run the tests, type make test in your turn-in folder.

Mutual exclusion (mutex.c)

This is a warm-up exercise.

Reusable Barrier (barrier.c)

This is the problem we discussed in class at some length. Implement first a disposable barrier, then a reusable barrier using semaphores.

Worker Threads 1 (worker1.c)

Here the scenario is a multi-threaded web server. To avoid the overhead of thread creation, and the risk of overloading the CPU, threads are created on startup only. As requests come in, they are served by existing threads as they become available.

Implement the functions wait_for_service() and wait_for_request(). Ensure that every incoming request is eventually served, all threads are working when there are requests waiting to be served, and no threads are working (using CPU) when there are no requests to be served. Don't worry about coordinating which worker thread gets which request - just make sure wait_for_service_request() doesn't return before the request has been fetched by a worker, and that wait_for_request() doesn't return before a request is ready to be processed.

Worker Threads 2 (worker2.c)

In this version, the server has two types of threads - front-end threads that communicate with the remote browser and apply templates to produce the final HTML document, and back-end threads that perform computational tasks and deliver raw content to the front-end thread.

Threads call the functions front_ready() and back_ready() when they have finished processing the last request. These in turn call group() to create a grouping of front/back end threads for the next request.

Every request requires two back-end threads and one front-end. A correct solution must make sure that every group has two back-ends and one front-end. That is, if we print out the thread type for every call to group() and divide the resulting list into groups of three, every group should have two back-ends and one front-end.

Turn-in instructions

Do not edit the files named *_test.c, and do not use any built-in synchronization operator other than semaphores. Feel free to build and use your own operators out of semaphores though.

This is the same as every previous homework. Make sure you run make test on your solution, on your Amazon EC2 VM, before committing your final version.

Edit | Attach | Print version | History: r8 < r7 < r6 < r5 < r4 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r6 - 2013-11-12 - 06:09:48 - Main.jakob
Copyright 2016 The Board of Trustees
of the University of
Helping Women Faculty Advance
Funded by NSF