moved setting signal inside critical section to avoid possible race.