COSC 4330 SECOND MIDTERM NAME:_______________________ CLosed Book. You can have one sheet of notes. 1. For each of the statements below, indicate in one sentence whether the statement is true or false (2 points), and why (3 points). (a) Monitor conditions can only have positive values. (b) Most programmers like to put all their signal operations at the end of their monitor procedures. (c) Critical sections are consumable resources. (d) Peterson's algorithm assumes the existence of shared variables. (e) One cannot prevent deadlocks in client/server systems. (f) One cannot initialize binary semaphores. 2. Complete the following sentences: (4X×5 points) In some implementations of monitors the signal operation is replaced by a _______________________________ operation. In Java, a monitor procedure must start with the two keywords public and ___________________________________. You should use streams rather than datagrams when you have to transmit ______________ quantities of data. The main disadvantage of atomic transactions is that they are ____________________________________________________________ 3. Consider the function double_trouble(int *pa, int *pb){ (*pa) += 5; (*pb) += 5; } //double_trouble and assume the following calling sequence: int alpha = 10; double_trouble(&alpha, &alpha); What will be the value of alpha after the call assuming that: (a) the call was a regular procedure call: __________ (5 points) (b) the call was a remote procedure call? __________ (5 points) 4. Write one short idempotent procedure in any reasonable approximation of C and explain in a single sentence why it is idempotent. (2×5 points) 5. Fill the blanks in the following solution to the mutual exclusion problem. (4X5 points) void enter_region(int *plock) { int private = ______; while(private == ______) swap(__________, &private); // single instruction } // leave_region void leave_region(int *plock) { ____________ = 1; } // leave_region 6. Consider the following solution to the mutual exclusion problem and explain when it fails and what will be the result of such failure. (2X×5 points: I do not care about how you could fix it.) int must_wait; // process that must wait int enter[2] = {0, 0}; void enter_region(int pid) { enter[pid] = 1; must_wait = pid; while (enter[1 - pid] || must_wait==pid); } // enter_region void leave_region(int pid){ enter[pid] = 0; } // leave_region