Answer the question
In order to leave comments, you need to log in
Is the code that produces unique numbers based on a timer correctly written?
// timer — общий на всю прогу atomic<long long>
// Можно рассчитывать только на 64-битную архитектуру
long long newTime = someUtcTime();
long long oldTime = timer;
do {
newTime = std::max(newTime, oldTime + 1); // должен быть больше того, что имеется
} while (!timer.compare_exchange_strong(&oldTime, newTime))
return (oldTime = newTime);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question