COSC 4330 QUIZ #2 April 7, 1997 CLOSED BOOK. You can have one sheet of notes. Each question is worth 20 points. 1. Consider the function transfer (int *pa, int *pb, int amount) { *pa = (*pa) + amount; *pb = (*pb) - amount; } and assume the following calling sequence: alpha = 10; beta = 20; transfer (&alpha, &alpha, 5) What will be the value of alpha after the call assuming: (a) The call was a regular procedure call: _____10______ (Nothing changes because the same address gets first incremented then decremented) (b) The call was a remote procedure call? _____ 5______ (Alpha gets first assigned the new value (alpha + 5) then the value (alpha - 5)) 2. What is the major advantage of using a test-and-set instruction to ensure mutual exclusion rather than using kernel-supported semaphores? Test and set can be used to guarantee mutual exclusion without requiring system calls. They are used in multiprocessor systems to synchronize tasks running on different processor when the critical sections are short it is then better to let a processor waste a few cycles doing a busy wait than having to go to four context switches (two for the P() operation and two for the V() operation). 3. What is the major advantage of atomic transactions? Atomic transactions implement an all or nothing semantics. Hence the client will never have to deal with remote procedure calls that were only partially executed. 4. What should the kernel do when it executes a V( ) call on a semaphore? If the semaphore queue is not empty, the kernel selects one process from the queue and puts i in the ready queue. If the semaphore queue is empty, the kernel increments by one the semaphore value. 5. State the four criteria that any solution to the critical section problem should satisfy. (1) No two processes may be simultaneously into their critical sections for the same shared data. (2) No assumptions may be made about the speeds at which the processes will execute. (3) No process should be prevented to enter its critical section when no other process is inside its own critical section for the same shared data. (4) No process should have to wait forever to enter its CS (starvation). --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 added and other deleted almost every semester. ----------------------------------------------------------------