wrote the semaphore code