we have to lock both state and thread