COSC 4330 QUIZ #2 November 15, 1995 CLOSED BOOK. You can have one sheet of notes. Each question is worth 20 points. 1. What is wrong with the following solution to the mutual exclusion problem for two processes: 1. int tie_breaker; 2. int want[2]= { 0, 0}; 3. void enter_region(int pid) // pid must be 0 or 1 4. { 5. want[pid] = 1; 6. tie_breaker = pid; 7. while (want[1-pid] && tie_breaker != pid); 8. } // enter_region 9. void leave_region(int pid) // pid must be 0 or 1 10. { 11. want[pid] = 0; 12. } // leave_region ___ it does not guarantee mutual exclusion under all circumstances ___ it may lead to deadlocks ___ it may prevent a process to enter its critical section even though no other process is accessing the shared data 2. To avoid this problem, line number ____ should be replaced by 3. What makes an instruction such as the test and set instruction (TSET) discussed in class especially useful for writing user-level solutions to the mutual exclusion problem? 4. What is the major advantage of kernel-supported semaphores? 5. Rewrite the following fragment of monitor code assuming that all signal operations in the monitor are replaced by notify operations: if (nfullslots == 0) notempty.wait; take_item_from_buffer(&item); nfullslots--; notfull.signal; --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. ----------------------------------------------------------------