A semaphore is a variable or data type that is used for controlling access by multiple processes or threads to a common resource.
A semaphore can be seen as a record or counter of how many units of a particular resource are (still) available. There have to be methods to adjust the counter/record when units are getting used (required/acquired) and get free (released) again.
Semaphores are another way to prevent race conditions, even though their use is no guarantee that a program is free from these problems.
Semaphores which allow an arbitrary resource count are called counting semaphores, while semaphores which are restricted to the values 0 and 1 (meaning locked/unlocked, unavailable/available) are called binary semaphores.