added semaphore solution