I am create another thread and expecting another thread terminates after main terminates. however the process hangs
std::mutex mtx;
std::condition_variable cv;
std::unique_ptr<std::thread> g_t;
void func()
{
std::this_thread::sleep_for(std::chrono::seconds(3));
std::cout << "func";
}
int main()
{
std::thread t(func);
t.detach();
std::cout << "main";
return 0;
}
I am confused, because the process shall terminates once all threads terminates.
Aucun commentaire:
Enregistrer un commentaire