fix deadlock

A quick fix. It is time for me to review all the codes and remove all the unnecessary locks tonight.