I would like to detect thread end in c++11 but I don't know how to do, it's look like that "get" block program, here is what I've done:
void Object::init()
{
this->thread = std::async( std::launch::async, &State::load, stateInstance );
}
/* A method in a loop */
void Object::run()
{
bool ready = this->thread.get();
if( ready )
{
/* do something */
}
else
{
/* draw interface, manage event, … */
}
}
My program don't go in the "else" in "run" method, program is stuck on "this->thread->get()" while state isn't load.
How can I handle that?
Thanks!
I'm unsure what the trouble is, but here's an idea using
wait_for
(compiled on Coliru):