Ending a thread

While (condition)
{
if (condition)
{
thread t1(FuncName, parameters);
t1.detach();
}
if (condition)
{
* something *
}
// Need to wait here, at the end of the while untill the thread t1 ends
}

I know there is the option of t1.join(), but I cannot use it since I used t1.detach()... (if I wont use it, I cant get out of the if condition without breaking the thread, which gives a runtime error)...

Maybe I can check if the thread is alive or not, and use it in a while loop
EX. while(thread.alive())

So I need to add insted of the note a line that wait untill thread t1 ends, and then go into the while loop again...