Add a with_lock function to ensure commitnumber appends do not interweave.