As for the wait, just use thread::timed_join()inside the main thread, this will return falseif the thread has not completed within the set time.
Killing a thread is not possible if your third-party library is not aware of boost: threads. In addition, you almost certainly do not want to “kill” the stream without giving the function the ability to clean up.
I would suggest that you wait, say, 2 seconds, and then continue with some kind of error message, allowing the framework function to complete its work and simply ignore the result if it arrives too late.
Regarding the return value, I would suggest something like
struct myfunction {
MyObj returnValue;
void operator() () {
returnValue = theComputedReturnValue;
}
};
myfunction f;
boost::thread t = boost::thread(boost::ref(f));
t.join();
use(f.returnValue);
source
share