



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




(a) int turn; /* shared */
void MyThreadFunc (int i) { while (TRUE) { compute(); while (turn != i) // do nothing ; execute_code_in_critical_section(); turn = (i + 1) mod 2; } } turn = 1; CreateThread(MyThreadFunc, 0); // pass “0” as the argument to “MyThreadFunc” CreateThread(MyThreadFunc, 1);
(b) boolean flag[2]; /* shared */
void MyThreadFunc (int i) { while (TRUE) { compute(); while (flag[(i+1) mod 2]) // do nothing ; flag[i] = TRUE; execute_code_in_critical_section(); flag[i] = FALSE; }
flag[0] = flag[1] = FALSE; CreateThread(MyThreadFunc, 0); CreateThread(MyThreadFunc, 1);
(c) boolean flag[2]; /* shared */
void MyThreadFunc (int i) { while (TRUE) { compute(); flag[i] = TRUE; while (flag[(i+1) mod 2]) // do nothing ; execute_code_in_critical section(); flag[i] = FALSE; } } flag[0] = flag[1] = FALSE; CreateThread(MyThreadFunc, 0); CreateThread(MyThreadFunc, 1);
Allocation Max Available A B C D A B C D A B C D P0 0 0 1 2 0 0 1 2 1 5 2 0 P1 1 0 0 0 1 7 5 0 P2 1 3 5 4 2 3 5 6 P3 0 6 3 2 0 6 5 2 P4 0 0 1 4 0 6 5 6
a. What is the content of the matrix Need? b. Is the system in a safe state? c. If a request from process P1 arrives for (0,4,2,0), can the request be granted immediately?
Problem Statement #1 (“Emmet Street Rope Bridge”): President Casteen is considering adding a rope bridge across Emmet Street to give students another option for moving between parts of the campus. The rope can hold up to 7 people at one time. Furthermore, all people on the bridge must be moving in the same direction. Design a simulation (one thread per person), such that once a person begins crossing the bridge is guaranteed to make it across. Furthermore, a continuous stream of students crossing in one direction should not “starve” the people attempting to cross in the other direction. (President Casteen will take your simulation and vary the arrival rate of students attempting to cross in each direction, and measure the effectiveness of the potential bridge).
Problem Statement #2 (“coolness”): Students in the dining hall invoke dine and then leave. After invoking dine and before invoking leave a student is considered “ready to leave”. The synchronization constraint that applies to students is that, in order to maintain the illusion of social suave, a student may never sit at a table alone. A student is considered to be sitting alone if everyone else who has invoked dine invokes leave before she has finished dine.
Problem Statement #3 ("Dorm Problem"): Given a set of dorm rooms, twice as many students to fill them, and a survey of interests by the students, find an assignment of pairs of roommates that minimizes the disharmony (measure of how divergent the interests of roommates are) between the total set of students.
Some information that you might find helpful :
Each program must be properly and reasonably designed, documented, implemented, and tested/evaluated. The grading for this part of the assignment will be:
You must both hand-in your solutions to these questions at the beginning of class on Tuesday Nov 20 AND email an electronic copy of your solutions to [email protected] by 11:00am on Tuesday Nov 20. Make sure that both documents clearly contain your name. Each person should submit his/her answers to part 1 individually, and then a team should submit one solution for part 2.