How can I check if thread has finished work in C++11 and above? I have been reading the documentation and I have written the following code:
#include <iostream>
#include <thread>
void mythread()
{
//do some stuff
}
int main()
{
std::thread foo(mythread);
if (foo.joinable())
{
foo.join();
//do some next stuff
}
}
joinable
tells only that the thread has started work, but I would like to know how to write code to check if the thread has finished work.
For example:
#include <iostream>
#include <thread>
void mythread()
{
//do some stuff
}
int main()
{
std::thread foo(mythread);
if (foo.finishedWork())
{
foo.join();
//do some next stuff
}
}