Next: Semaphores
Up: No Title
Previous: Disable interrupts
- Use binary indicators to control access to a shared resource
- L = 1 (means resource is unavailable (locked)
L = 0 (means resource is free (unlocked)
- Primitive operations on locks
LOCK(L) ::= when L=0 do L=1 ;
UNLOCK(L) :: L=0 ;
- Mutual exclusion can be obtained using locks
PROCESS P[i] ;
begin
LOCK(L) ;
{critical section}
UNLOCK(L) ;
end
Implementation of Locks
- The indivisible TESTandSET instruction
- single instruction that reads a variable, stores its value in an allocated area
(critical section), and then sets the variable to a certain value
- Instruction once initiated will complete all operations without interruption
- It is difficult to use, understand and verify -and is also wasteful
Omer F Rana
Tue Feb 11 19:19:09 GMT 1997