Otherwise TSAN is rightfully complaining that there is a data race
because several threads are updating at the same time. While the
impact of this counter being corrupted is almost zero, and there is
an actual overhead to making it atomic, I believe this is the only
correct way to ensure the expected behaviour of this policy.
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
return std::nullopt;
}
- static unsigned int counter;
+ static std::atomic<unsigned int> counter{0};
size_t serverIdx = (counter++) % servers.size();
auto currentServer = servers.at(serverIdx);