Start multiple threads without joining

c++, c++11, multithreading

Solution

Try this

for (int i = 0; i < 10; ++i) {
    std::thread{myfunction, i, param2, param3}.detach();
}

Or if you want to join the threads later, then put them in a `std::vector`.

std::vector<std::thread> v;
for (int i = 0; i < 10; ++i) {
    v.emplace_back(myfunction, i, param2, param3);
}

// Do something else...

for (auto& t : v) {
    t.join();
}

Problem

(how) can i start multiple threads like this: ``` for (i = 0; i < 10; i++) { std::thread (myfunction, i, param2, param3); } ``` without joining?

Original source