Add lock to threading