Add lock, acquire and release function in thread