Lets say I have the following class
class A
{
public:
A()
{
my_thread=std::thread(std::bind(&A::foo, this));
}
~A()
{
if (my_thread.joinable())
{
my_thread.join();
}
}
private:
std::thread my_thread;
int foo();
};
Basically, if my thread completes between the joinable and join calls, then my_thread.join
will wait forever? How do you get around this?