I have a class object, which in some cases only requires a thread to start. In the destructor, it would be convenient for me to know whenever there is / was a thread. The question is how to determine if the object was std :: thread or is a valid thread.
class MyClass
{
public:
~MyClass()
{
if(mythread is a valid object)
mythread.join();
if(mythread was a valid object in its lifetime)
Do some stuff
}
void DoSomeStuff()
{
}
private:
std::thread mythread;
};
source
share