operating system - Why semaphore? -
why use binary semaphores when same functionality can achieved simple variable ?
because semaphore isn't simple variable, it's larger construct that.
specifically, counting semaphore (which binary semaphore is, effectively, count of 1), there's added capability of blocking process/thread tries increment semaphore above maximum value.
semaphores have additional facility state changed "atomically", means underlying memory surrounded logic ensure cpu caches , such flushed, , when value changed, it's changed "everyone". particularly important on modern multi-core processors.
the semaphore appropriate use when trying guard shared resource on use. binary semaphore perfect resources can used 1 process/thread @ time.
Comments
Post a Comment