Question - What is semaphore?
Answer -
Semaphore is a special variable, it has two methods: up and down. Semaphore performs atomic operations, which means ones a semaphore is called it can not be inturrupted.
The internal counter (= #ups - #downs) can never be negative. If you execute the “down” method when the internal counter is zero, it will block until some other thread calls the “up” method. Semaphores are use for thread synchronization.