用atomic
#include <atomic> #include <iostream> int getNextSerial() { static std::atomic<uint64_t> i; return i++; } int main() { for (int a = 0; a < 34; ++a) { std::cout << getNextSerial() << std::endl; } }
用atomic
#include <atomic> #include <iostream> int getNextSerial() { static std::atomic<uint64_t> i; return i++; } int main() { for (int a = 0; a < 34; ++a) { std::cout << getNextSerial() << std::endl; } }