finish version with semaphore