replace mutex lock with semaphore