Use semaphore instead of mutexes