why is semaphore used
This is particularly important on modern multi-core processors. The semaphore is appropriate to use when you are trying to guard a shared resource from over use. A binary semaphore is perfect for resources that can only be used by one process/thread at a time.