network_utils: fix TSAN detected race

master
Andre Puschmann 4 years ago
parent 3173dedf0a
commit bbcaa49429

@ -154,7 +154,7 @@ private:
// state // state
std::mutex socket_mutex; std::mutex socket_mutex;
std::map<int, recv_callback_t> active_sockets; std::map<int, recv_callback_t> active_sockets;
bool running = false; std::atomic<bool> running = {false};
int pipefd[2] = {-1, -1}; int pipefd[2] = {-1, -1};
std::vector<int> rem_fd_tmp_list; std::vector<int> rem_fd_tmp_list;
std::condition_variable rem_cvar; std::condition_variable rem_cvar;

@ -459,7 +459,7 @@ void socket_manager::run_thread()
FD_SET(pipefd[0], &total_fd_set); FD_SET(pipefd[0], &total_fd_set);
max_fd = std::max(pipefd[0], max_fd); max_fd = std::max(pipefd[0], max_fd);
while (running) { while (running.load(std::memory_order_relaxed)) {
memcpy(&read_fd_set, &total_fd_set, sizeof(total_fd_set)); memcpy(&read_fd_set, &total_fd_set, sizeof(total_fd_set));
int n = select(max_fd + 1, &read_fd_set, nullptr, nullptr, nullptr); int n = select(max_fd + 1, &read_fd_set, nullptr, nullptr, nullptr);

Loading…
Cancel
Save