|
|
|
|
|
by ot
337 days ago
|
|
No, the timer is still global (that's why you need the compare-and-swap). But the threads only need to do reads most of the time, and reads do not cause contention. Writes do. It looks something like this (pseudocode): static std::atomic<uint64_t> deadline{0};
auto now = coarse_clock::now();
auto curDeadline = deadline.load(std::memory_order_relaxed);
if (now >= curDeadline &&
deadline.compare_exchange_strong(curDeadline, now + period, std::memory_order_relaxed)) {
// Actually log
}
|
|