What is a semaphore? How do they work? (Example in C)