Reusing a std::thread object would look something like this:
#include <thread> void foo() { // do stuff... } void bar() { // do stuff... } //... std::thread thObject (foo); //first use //... thObject = std::thread(bar); //reuseSeems simple. However, there is a limitation: the thread object must not be joinable when reusing it, otherwise it will throw an exception.
So make sure you call join() on the thread object before reusing it.
This rule does not apply for detached threads.
No comments:
Post a Comment