COSC 4330 QUIZ #2 Thursday, April 8, 1999 CLOSED BOOK. You can have one sheet of notes. Each question is worth 20 points. 1. Consider the function doubledouble(int *pa, int *pb){ *pa = 2*(*pa); *pb = 2*(*pb); } //doubledouble and assume the following calling sequence: int alpha = 10; doubledouble(&alpha, &alpha) What will be the value of alpha after the call assuming: (a) The call was a regular procedure call: ____40_______ (b) The call was a remote procedure call? ____20_______ 2. What is very wrong with the following monitor statement? condition notfull = 0; YOU CANNOT INITIALIZE MONITOR CONDITIONS AS THEY HAVE NO VALUE. 3. What is very wrong with this piece of code? You can assume that mutex is a mutual exclusion semaphore. (Hint: you do not need to understand the problem to find the error.) producer() { struct xyz item; for(;;) { produce(&item); P(&mutex); if (nfreeslots == 0) continue; //buffer full put(item); V(&mutex); } // for } // producer */ WHEN THE PRODUCER ENCOUNTERS A FULL BUFFER, IT DOES A BUSY WAIT *INSIDE* THE MONITOR< WHICH GUARANTEES A DEADLOCK. 4. What is the major use of the UNIX semctl() system call? DESTROYING SEMAPHORE ARRAYS. 5. How could you prevent deadlocks by denying the hold and wait condition in the dining philosophers problem? FORCING ALL PHILOSOPHERS TO GET EITHER BOTH LEFT OR RIGHT FORKS OR NEITHER OF THEM. --IMPORTANT----IMPORTANT----IMPORTANT----IMPORTANT----IMPORTANT-- Please do not try to answer these questions by yourself BEFORE having a clear idea of what's on the test for which you are studying. Materials covered in each test DO VARY from semester to semester because the pace of the course can change, some materials are be added and other deleted almost every semester. ----------------------------------------------------------------