change to semaphore ,not tested yet