Usually semaphore is used to allow a certain number of threads to access the resources at the same time. So it is possible for two or more than two threads to access the same resource at the same time, which means there is potential danger of race condition. I wander how semaphore manages to synchronize the access of the resource? Thanks for your inputs.