replace semaphore with signal and wait