Mutual exclusion by disabling interrupts, lock variables

Mutual exclusion by disabling interrupts: Mutual exclusion can be achieved by disabling interrupts for each process after they enter their critical region. The interrupts can be enabled after they leave their critical region. The idea is that when all interrupts are disabled CPU will not be able to switch from one process to another as it does by using the clock interrupt. So, when a process updates something, no other process can access it, thus providing mutual exclusion. The only disadvantage in this method is that there is too much power given to a process. A process can may or may not enable the interrupts at the later time.

Mutual exclusion by lock variables: A shared lock variable can be used for this purpose. It can be set to 0 to specify that there is no process in critical region. Only when a process see that the lock variable is set to 0 it enters its critical region. Now, when it enters its critical region it sets the lock to 1. So other processes see that lock variable is set to 1 they won’t go in their critical region. This method has a problem, say one process see that lock is set to 0, now, simultaneously another process can see that an enter its critical region by setting the lock to 1.

Leave a Reply