You can use sem_wait and sem_post operations on semaphore