Fix some bugs regarding mutex.