Here is an example code:
struct T
{
T()
{
task = std::async(std::launch::async, [this]()
{
while(work)
{
//do something
}
});
}
~T()
{
work = false;
}
std::future<void> task;
std::atomic_bool work;
};
Should I somehow finalize future in the destructor or the above code is ok ?