Fixed lock issue for multi-threads.