In C++ I have an std::vector of threads, each running a function running forever [while(true)]. I'm joining them in a for loop:
for (auto& thread : threads)
{
thread.join();
}
When the program finishes I'm getting a std::terminate() call inside the destructor of one of the threads. I think I understand why that happens, except for the first thread the other join calls don't get called.
What is the correct way of joining those threads? And is it actually necessary to join them? (assuming they are not supposed to join under normal circumstances)