I want to determine if a given thread is still running or has already
completed. I thought the joinable() method would provide this information,
but unfortunately it seems that a thread does not automatically become
Not-A-Thread after completion. I wrote a small app to verify this:
<code>
#include <iostream>
using namespace std;
#include
#include
#include
using namespace boost;
using namespace boost::posix_time;
mutex ioMutex;
void f()
{
mutex::scoped_lock lock(ioMutex);
cout << "done" << endl;
}
int main(int argc, char** argv)
{
boost::thread t(f);
while (t.joinable())
{
{
mutex::scoped_lock lock(ioMutex);
cout << "not yet done" << endl;
}
this_thread::sleep(seconds(2));
}
return 0;
}
</code>
Output:
not yet done
done
not yet done
not yet done
...
So what should I do instead if I want to know if a thread is still running?
Best regards,
Alexander Heinrich