Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why all the interrupts must be disabled during semaphore operations?

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?

like image 640
Sanketssj5 Avatar asked Oct 19 '22 06:10

Sanketssj5


1 Answers

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.

like image 106
Tim Biegeleisen Avatar answered Oct 22 '22 21:10

Tim Biegeleisen