WED DEC 14
• final is Fri Dec 16, 11:30 am, OS415
• final is open-book, open-notes
• see final dir for 3 images of whiteboard
• info on Palm mem mgr pdf uname & passwd are our 5-digit course #

WED DEC 7
• reference string, distance string, Belady's anomoly, analysis of FIFO stack algorithms
assignment 10: Palm database + exercises html
DUE WED DEC 14

MON DEC 5
paging algorithms: optimal, FIFO, 2nd chance, clock, NFU, aging, working set, w.s. clock
theory: locality, pre-paging, reference string

FRI DEC 2
assignment 9: page tables pdf
due Dec 5

FRI NOV 18
• Palm OS memmgr handout; handle-based mem alloc'n
• buddy system details – see Wikipedia link
• use binary tree to implement the buddy mgr!

WED NOV 16
assignment 8: memory manager pdf
due Wed Nov 28
• first-fit, best-fit, data structures for asn 8

MON NOV 14
• Quiz 2 on Nov 30, will cover Asn 1 – 7
• rest of semester: memory management (alloc & virtual memory), file systems (Unix F/S & Palm D/B)
• asn 7: normal and bursty fcns modified over weekend
• today: malloc, first fit, best fit, worst fit, intro to handles

WED NOV 9
asn 7 updated; went over asn7 code

TUE NOV 8
assignment 7: sleeping barber html
due Wed Nov 16

MON NOV 7
quiz returned, threads discussion

FRI NOV 4
IPC problems: dining philo, sleeping barber

WED NOV 2
monitors and message passing

FRI OCT 28
assignment 6: Donut Factory (full) pdf due Mon Nov 7
ASN 5 CUT-OFF WED NOV 2

WED OCT 19
assignment 5: Donut Factory Prep pdf due Wed Oct 26
ASN 3 CUT-OFF FRI OCT 21

WED OCT 12
quiz 1: M Oct 24
quiz 2: W Nov 30

MON OCT 3
assignment 4: OSP CPU scheduler pdf due Wed Oct 12

MON SEP 26
assignment 3: Palm OS performance html due Fri Sep 30

FRI SEP 23
lecture 8 notes txt
resource IDs; adding to Hello2 app

MON SEP 19
lecture 6 notes txt
intro to Palm OS dev
assignment 2: intro to Palm OS dev html due Fri Sep 23

FRI SEP 16
lecture 5 notes txt
intro to Palm OS
Zen of Palm pdf

WED SEP 14
lecture 4 notes txt
signals

MON SEP 12
lecture 3 notes txt
exec and unnamed pipe

FRI SEP 9
lecture 2 notes txt
assignment 1: processes, pipes, signal handers pdf due Fri Sep 16

To format for printing, click here.

resources palm OS Yahoo! Group assn cover helpful links

91.308 Assignment 7:
Threads and the Sleeping Barber Problem

out: Tue Nov 8
modified: Wed Nov 9
due: Wed Nov 16

Introduction

In this assignment, you will use Unix pthreads (“Posix threads”) in an implementation of the Sleeping Barber problem.

Customers (who need haircuts) come to a barber shop and fill the seats in the shop, waiting in line. When a customer is available, the barber wakes up and gives him a haircut, and the customer leaves. If too many customers are waiting (i.e., the seats are full), arriving customers leave without being served (lost customers == bad). (See Tanenbaum pp. 129–132 for a full exposition of the problem.)

The Sleeping Barber problem is a classical IPC (inter process communication) problem that models waiting queues (e.g., a telephone service call center).

Details

In this assignment, you will instrument and experiment with the performance of a working implementation of the Sleeping Barber problem. The implementation is written in C and uses pthreads to implement the customer and barber processes.

Following are specific instructions on what to do.

  • On Mercury, make a local copy of the file ~fredm/308/barber/barbershop.c. Compile it with gcc -pthread -lm barbershop.c -o barbershop. Run your barbershop binary to demonstrate that it works.

  • PROBLEM 1. In the default implementation, it takes 0.1 second to cut hair (10 haircuts/second), but customers arrive every 0.01 seconds (100 customers/second). Therefore, on average, for every 100 customers that arrive, only 10 will be served, and 90 will leave.

    Add code to the implementation that keeps track of how many customers are successfully served and how many customers leave without getting a haircut.

    Then, after the 1000 customers arrive, add code to print out the results: how many were served and how many left? Answer the following questions:

    1. Is the result the same every time you run the code?
    2. Do the results match the expections (10% success rate)?
    3. If not, why not?

    Include your new instrumented code in your writeup, with your changes highlighted.

  • PROBLEM 2. Change the customer arrival rate to match the barber rate of 0.1 seconds. Now, customers arrive just as quickly as they can be served, so it should be possible to have a 100% success rate. Does it occur? Why or why not? If not, why?

  • PROBLEM 3. Now, change the customer arrival rate to use one of the three randomized delays. Each of the delays will provide a randomized value between 0.001 seconds and 0.2 seconds, but has an average delay of 0.1. So in principle, all customers can be served (since the average arrival rate equals the haircut rate).

    However, there are three different distributions of random numbers: flat (an even distribution; all values are equally likely), normal (a bell-shaped curve, with values in the middle more likely than at the extremes), and bursty (an upside-down normal curve, with values at the extremes more likely).

    Run your simulation with each of the three arrival functions, and answer the following:

    1. What results (success rate) do you get for each of the three arrival functions?
    2. Which yields the best performance? Which the worst?
    3. Explain these results.
    4. For the function that performed the worst, increase the queue length (i.e., the number of seats in the barbershop) until the simulation's performance matches the results of the best arrival rate (when there are 5 seats). How many seats does the simulation require to handle the hardest arrival function as well as the easiest?

  • PROBLEM 4. Modify your code to launch two barbers, each running at 0.2 seconds per haircut. This simulation has the same maximum throughput as the earlier ones (10 customers/second).

    But does it perform differently? Run the simulation (make sure to reset the number of seats back to 5) with the 3 arrival functions. Make a table of typical performance for each of the 3 arrival functions, and compare the results to 1 barber @ 0.1 sec/haircut.

Turn In

Turn in the following:

  1. A full printout of your instrumented barbershop.c program. Highlight your changes. Make sure to provide a working path to the code on your cover sheet.

  2. For each problem, a table showing results, and a 2- to 3-paragraph discussion that explains them.

Links

http://www.cs.nmsu.edu/~jcook/Tools/pthreads/pthreads.html

http://www.cc.gatech.edu/classes/AY2000/cs6210_spring/pthreads_tutorial.htm

http://www.llnl.gov/LCdocs/pthreads/pthreads.pdf local copy

Mods

  • Changes as of Fri Nov 11 18:49:27 2005: normal and bursty are implemented with trigonometric functions. Please add the -lm flag when compiling.

Last modified: Friday, 11-Nov-2005 18:50:52 EST by fred_martin@uml.edu