Implementation of Semaphore in C