Implemented a lock using a semaphore of 1