I think an atomic variable should be used here to make it thread-safe.
See base/atomic_sequence_num.h for reference.