Reason why somebody would be interested in
//...
new std::thread (func,arg1,arg2);
}
is that std::thread
destructor(unlike boost::thread
) kills the thread. func finishes is some time.
My question is this safe in cases:
Case 1: lets say that function takes arg1, arg2 by value.
Case 2: lets say that function takes arg1, arg2 by reference-this sounds bad if you ask me, because I presume that at the end of the scope where thread is created arg1 and arg2 will be cleared by their destructors.
BTW is std::thread destructor(that is AFAIK called when func finishes) smart enough to clear all the resources used by thread? I mean if I create 1M threads(ofc not at the same time) with new and all of them finish, have I leaked anything permanently?