Controlling Interrupts
This lesson discusses the pros and cons of manipulating interrupts as a mechanism for locks.
We'll cover the following...
One of the earliest solutions used to provide mutual exclusion was to disable interrupts for critical sections; this solution was invented for single-processor systems. The code would look like this:
Press + to interact
void lock() {DisableInterrupts();}void unlock() {EnableInterrupts();}
Assume you are running on such a single-processor system. By turning off interrupts (using some kind of special hardware instruction) before entering a critical section, you ensure that the code inside the critical section will not be interrupted, and thus will execute as if it were atomic. When you are finished, you re-enable interrupts (again, via a hardware instruction), and thus the program proceeds as usual.