added line semaphore & wait for the thread to finish