Combine multiple threads in any order

I have an array of objects std::threadthat do not matter in what order they work and in what order they join the main thread. I tried using

for(int i = 0; i < noThreads; ++i)
{
    if(threads[i].joinable())
        threads[i].join();
}

but it seems that they work "in order", of course, it may be the fact that I am reaching this conclusion from the fact that the console output from the threads occurs in the order in which I send them (as in all output from stream # 1, and then all output from stream # 2). I also tried threads[i].detach(), but I do not know the execution time of each thread, so I can not pause the program until it ends.

The work performed by each thread is:

int spawn(const char* cmd)
{
    FILE *fp = popen(cmd, "r");

    char buff[512];

    if(vFlag == 1)
    {
        while(fgets(buff, sizeof(buff), fp)!= NULL)
        {
            printf("%s", buff);
        }
    }

    int w = pclose(fp);
    if(WIFEXITED(w))
        return WEXITSTATUS(w);
    else 
        return -1;
}

"./otherApp.elf". , , , , , , ?

+4
2

. join , .

, , , joinable , . . .

, , , .

Boost , , .

+2

( ).

, join , , for, , , (..) .

i.e. , joinable - : (, , ) ?

, , , , - , , . , , .

+1

All Articles