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
Alexander Heinrich
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.
That is true.
So what should I do instead if I want to know if a thread is still running?
Set a flag at the end of the thread function. Then, in other code, you can check the flag. If the flag is set then the thread is done. Anthony -- Author of C++ Concurrency in Action | http://www.manning.com/williams just::thread C++0x thread library | http://www.stdthread.co.uk Just Software Solutions Ltd | http://www.justsoftwaresolutions.co.uk 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
participants (2)
-
Alexander Heinrich
-
Anthony Williams