











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!












Interrupt enable/disable for atomicity
Lock impl. #1 (disable interrupts w/ busy waiting) Lock() { disable inerrupts while(value != FREE){ enable interrupts disable interrupts } value = BUSY enable interrupts } Unlock() { disable interrupts value = FREE enable interrupts }
Test_and_set(x) { tmp = X X = 1 return(tmp) }
Lock impl. #3 (int. disable, no busy wait) Lock() { disable interrupts if(value == FREE) { value = BUSY } else { add thread to wait queue for this lock switch to next thread } enable interrupts } Unlock() { disable interrupts value = FREE if(any thread waiting for this lock) { move wait thread to ready queue value = BUSY } enable interrupts }
Thread a enable interrupts }
Lock() { while(test&set(guard)) { } if(value == FREE) { value = BUSY } else { add thread to wait q switch to next run t } guard = 0 } Unlock() { while(test&set(guard)) { } value = FREE if(thread waiting for lock) { move thread to ready queue value = BUSY } guard = 0 }