I am reading Operating System Concepts by Galvin. In the semaphore section it says that all the interrupts to the processor must be disabled while modifying the value of semaphore. Why it is required?
If processor interrupts were allowed to take place during the modification of a semaphore's value, then it would be possible for this value to end up in an inconsistent state. During an interrupt, a certain set of instructions will execute. These instructions can, in principle, do the same things that any executing code can do. Specifically, the interrupt might use the value of the semaphore in its logic, or copy that value somewhere else. If the value be in an inconsistent state, this can break your code logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With