Not sure this is the only problem, but given what you shared, the main thread is not waiting for the worker threads to finish their tasks.
Per this answer: When the main thread exits, do other threads also exit?, the process will be terminated when the main thread returns from main()
.
Proposed fix:
int main() { // .. your logic here std::vector<std::thread> threads; for (int i = 0; i < 4; ++i) { std::thread t(send_data, server_ips[i], port, bufdata); threads.push_back(std::move(t)); } for (int i = 0; i < 4; ++i) { if (threads[i].joinable()) threads[i].join(); // wait for threads[i] to finish } // .. clean up}