Assignment 3 Solutions - Operating Systems | CS 570, Assignments of Operating Systems

Material Type: Assignment; Professor: Roch; Class: OPERATING SYSTEMS; Subject: Computer Science; University: San Diego State University; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-zb5
koofers-user-zb5 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 570 OPERATING SYSTEMS
ARIE OCH
MR
Assignment 3
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.
Part I – Questions, 20 points each
1. An adaptive mutex is a semaphore that makes a decision as to whether or not to busy
wait depending upon the state of other processes in a multi-processor system. When a
process attempts to wait on a semaphore, the following is done (for simplicity, we
consider a mutex between two processes only):
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?
2. Thread T1 launches threads T2, and T3:
T1entry(…) {
start thread T2 executing T2entry(T2 args);
start thread T3 executing T3entry(T3 args);
do_work;
// delta
}
T2entry(…) {
do_work;
// alpha
do_more_work;
}
pf3
pf4

Partial preview of the text

Download Assignment 3 Solutions - Operating Systems | CS 570 and more Assignments Operating Systems in PDF only on Docsity!

CS 570 OPERATING S YSTEMS

MARIE ROCH

Assignment 3

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.

Part I – Questions, 20 points each

  1. An adaptive mutex is a semaphore that makes a decision as to whether or not to busy wait depending upon the state of other processes in a multi-processor system. When a process attempts to wait on a semaphore, the following is done (for simplicity, we consider a mutex between two processes only):

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?

  1. Thread T1 launches threads T2, and T3: T1entry(…) { start thread T2 executing T2entry(T2 args); start thread T3 executing T3entry(T3 args); do_work; // delta }

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)

  1. Prove that the contribution of any given CPU burst in the heuristic for shortest process next will diminish to zero as time increases.
  2. Suppose the three processes have CPU bursts as follows:
    • Process 1: 12, 3 MS
    • Process 2: 8, 7 MS
    • Process 3: 15, 22 MS

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?

Part II – POSIX programming assignment 120 points

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:

  1. The program should take the following optional command line arguments:

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.

What to turn in

ƒ 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.