


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Professor: Roch; Class: OPERATING SYSTEMS; Subject: Computer Science; University: San Diego State University; Term: Unknown 1989;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Part I must be done individually. Part II may be done with a pair programmer if desired. As with all assignments in this class, qualitative questions should be answered with grammatically correct sentences.
Due, Wednesday, Apr 9th^ at the beginning of class.
wait (Semaphore S) { S.value = S.value - 1; if (S.value < 0) { /* Some other process P holds the semaphore / P = process in critical region for semaphore S; if (state(P) == running) { while (S.value < 0) / busy wait */ no-op; } else { add calling process to wait list for S; block calling process; } } }
What is the rationale for providing such a semaphore?
T2entry(…) { do_work; // alpha do_more_work; }
T3entry(…) { do_work; // beta; } Add synchronization code such that T1 cannot reach point delta before T2 and T reach alpha and beta. Do it using both: a. semaphores b. messages sent to ports (port numbers as you see fit and assume an infinite capacity buffer)
Assume for simplicity that: context switches take 0 MS, each I/O burst can be handled instantaneously (the process returns to the ready queue immediately ready to start its next CPU burst), and that all processes start simultaneously with process 1 first, 2 second, and 3 third. What is the average wait time for all processes using round robin with a 10 MS time quantum? Shortest process next?
Suppose that Lucy and Ethel have gone to work for the Mizzo candy factory. Mizzo produces two types of candy: crunchy frog bites and everlasting escargot suckers. Unlike their last job, Mizzo has automatic flow control on their assembly line. No more than 10 candies are on the conveyer belt at any given time.
Crunchy frog bites tend to be more expensive than escargot suckers, so Mizzo has implemented a policy to prevent putting too many frog bites in the same box. No more than 3 frog bites can be on the conveyer belt at any given time. (Candies are taken off the line in the order that they are produced.)
Write a program using POSIX unnamed semaphores and POSIX threads to simulate this multiple producer and multiple consumer problem. POSIX unnamed semaphores are covered in the frequently asked questions section of the course home page.
Your program must meet the following design criteria:
Ethel consumed 22 crunchy frog bites + 24 escargot suckers = 46
Each candy generator should be written as a separate thread. The consumer processes (Lucy & Ethel) should share common code, but should also be separate threads.
If you are having difficulties understanding semaphores, my suggestion is to write this project in stages. First, make a single producer and consumer function on a generic candy type function. Then, add multiple producers and consumers. Finally, introduce the multiple types of candy. If you only get the multiple producer and consumer threads working with a single candy type (and meet the other criteria, e.g. separate compilation, etc.), you will earn a score of C.
If you had problems with the previous thread assignment, I suggest that you see me to ensure that you understand how threads work. While I do not distribute solutions to programs, I would be happy to let you look at a solution to the previous homework in my office.
HINT: One of the difficult problems for students is how to stop the program. Imagine that the Lucy thread consumes the 100th^ candy. The Ethel thread could be asleep, and thus never able to exit. The trick here is to use a barrier in the main thread. The main thread should block until consumption is complete.
Paper copy of your work including the program, Makefile, output with the parameters –f 600 –e 400 –L 300 –E 500. Pair programmers should turn in a single package containing the questions from part I (answered separately) and a single copy of the program. All students must fill out and sign either the single or pair affidavit and attach it to your work. A grade of zero will be assigned if the affidavit is not turned in. An electronic submission of programs shall be made in addition to the paper copy. A program comparison algorithm will be used to detect cases of program plagiarism. Remember that pair programmers should only submit one copy of their program.