thread1.detach(); if (thread1.joinable()) { thread1.join(); } else { cout << "thread1 detached!" << endl; }