Reputation: 249
I need a way to know if the thread I am running is finished or not. If it is not finished it wait and if it is finished print a successful message.
I don't find a method or something like that in c++11 from library thread.
I can't set a global variable because inside thread I am using execvp
and it does not return if successful.
Is there any way to do that? A method or flag or anything else.
Edit:
To make it clear I want to write a function that checks if thread is finished.
Upvotes: 1
Views: 5849
Reputation: 136256
You can use C++11 futures and promises:
Futures are a high level mechanism for passing a value between threads, and allow a thread to wait for a result to be available without having to manage the locks directly.
The benefits of futures over using plain threads are:
Surely, this can be done with plain threads, but why reimplement a wheel with C++11.
Upvotes: 6