CSE 131 Lecture 7: Lecture 7
Document Summary
Section 4. 4 in the freebsd textbook for asgn2. Require busy waiting: process spins in a loop waiting for something to happen, wasting cpu time. Several hardware methods (need a special instruction in hardware) Test & set: test a variable and set it in one instruction. Atomic swap: switch register & memory in one instruction. Compare_and_swap(register, old value, new value) returns success/fail. Ex: if we do this through hardware: if( var == 0) { set var = 1 ) swap(register, new value) returns old value. Instead of possibly another process taking over after the if . Turn off interrupts: process won"t be switched out unless it asks to be suspended. If you"re in a critical section, no switching will happen because interrupts are turned off. Still requires busy waiting but code is much simpler. Both hardware and software solutions require spin locks. Allow processes to sleep while they wait to execute their critical sections.