Professional Documents
Culture Documents
(Continues) : Complex Atomic Statements (
(Continues) : Complex Atomic Statements (
Exchange Instruction
Lock Instruction
Instruction performs while x = 1 do; x:= 1; where x is a memory location The process loops in the while until some other process unlocks it by x:= 0 Initially the local variable x is set to 0 Lock(x); <critical section> x:= 0;
4
The instruction is applicable to multiprocessor systems else the process will be deadlocked in an infinite loop. On a uniprocessor system, it can be interrupted only at the do; (do nothing, wait) part The instruction is not safe. When x = 0, only one process must sense it. Otherwise, more than one process may enter the CS
On most machines increment and decrement a memory location (or a register) is a single instruction which may be used for mutual exclusion
Disabling Interrupts
On a single CPU only one process is executed Concurrency is achieved by interleaving execution (usually done using interrupts) If you disable interrupts then you can be sure only one process will ever execute One process can lock a system or degrade performance greatly