fixed an bug caused by semaphore.