UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department | ||
CS 537
Spring 2001 | A. Arpaci-Dusseau | |
Quiz #3: Feb 21th -- Synchronization |
Name: | Student ID #: |
For each code sample, answer the following questions:
class Lock { private int turn = 0; public void acquire(int tid) { while (turn == (1 - tid)); } public void release(int tid) { turn = (1 - tid); } } |
class Lock { public void acquire() { disableInterrupts(); } public void release() { enableInterrupts(); } } |
class Lock { private int turn = 0; private boolean lock[2] = {false, false}; public void acquire(int tid) { lock[tid] = true; turn = 1 - tid; while (lock[1-tid] && turn == (1 - tid)); } public void release(int tid) { lock[tid] = false; } } |
class Lock { private boolean lock = true; public void acquire() { while (TestAndSet(lock, true); } public void release() { lock = false; } } |