Use precise memory orderings in load_tester

This commit is contained in:
2025-08-27 18:13:28 -04:00
parent b6e57f58af
commit 3d61408976

View File

@@ -401,6 +401,7 @@ private:
double current_min = g_min_latency.load(std::memory_order_relaxed);
while (latency < current_min &&
!g_min_latency.compare_exchange_weak(current_min, latency,
std::memory_order_relaxed,
std::memory_order_relaxed)) {
// Retry if another thread updated min_latency
}
@@ -408,6 +409,7 @@ private:
double current_max = g_max_latency.load(std::memory_order_relaxed);
while (latency > current_max &&
!g_max_latency.compare_exchange_weak(current_max, latency,
std::memory_order_relaxed,
std::memory_order_relaxed)) {
// Retry if another thread updated max_latency
}
@@ -637,7 +639,7 @@ int main(int argc, char *argv[]) {
int epollfd = g_epoll_fds[i]; // Each thread uses its own epoll instance
pthread_setname_np(pthread_self(),
("network-" + std::to_string(i)).c_str());
while (g_connect_threads.load() != 0) {
while (g_connect_threads.load(std::memory_order_acquire) != 0) {
struct epoll_event events[256]; // Use a reasonable max size
int batch_size = std::min(int(sizeof(events) / sizeof(events[0])),
g_config.event_batch_size);
@@ -779,7 +781,7 @@ int main(int argc, char *argv[]) {
continue;
}
}
g_connect_threads.fetch_sub(1);
g_connect_threads.fetch_sub(1, std::memory_order_release);
});
}