Semaphore control

Implementation can possilby lead to deadlocks