added semaphore mechanism