Semaphore operations are atomic because they are implemented within the OS _________.
GATE 1990 · Operating System · Semaphore · medium
Answer: Semaphore operations are atomic because they are implemented within the OS kernel, where the OS can disable interrupts or use hardware atomic primitives to prevent any interruption during the read-modify-write sequence.
Why atomicity is needed: If wait(S) is not atomic, two processes could simultaneously read S=1, both see it as positive, both enter the critical section — defeating mutual exclusion.
How the OS kernel ensures atomicity: Semaphore operations are implemented as system calls in the kernel. Inside the kernel, the OS can: (a) disable hardware interrupts before the operation and re-enable after (uniprocessor), or (b) use hardware atomic primitives (test-and-set, compare-and-swap) on multiprocessors. This ensures no context switch or concurrent access can occur during the operation.