add semaphore so that thread can wait