Add lock code, using flock to make sure only one at once