A thread-safe counter.