add locks for thread