Is there a way for an interruption point to not reset the interruption request flag before throwing? I have a Class accepting functions to be executed asynchronously this is implemented in terms of boost threads: T::operator()() { while (true) { foo(); boost::this_thread::interruption_point(); } } One of those functions performs some operations between a: try { /*code*/ } catch(...) { } this basically makes my Class not interruptible indeed that boost::this_thread::interruption_point() is useless if a boost::thread_interrupted has been catched inside the foo. I have found this: http://lists.boost.org/boost-users/2008/08/39106.php where the guys needs a way to reset it, I need a way to leave the flag on for the entire thread life if an interruption has been requested. Regards Gaetano Mendola --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus
On 11/04/2016 02:24, Gaetano Mendola wrote:
I have a Class accepting functions to be executed asynchronously this is implemented in terms of boost threads:
T::operator()() { while (true) { foo(); boost::this_thread::interruption_point(); } }
One of those functions performs some operations between a:
try { /*code*/ } catch(...) { }
this basically makes my Class not interruptible indeed that boost::this_thread::interruption_point() is useless if a boost::thread_interrupted has been catched inside the foo.
The recommended practice is to modify that to not swallow all exceptions: try { /* code */ } catch (const boost::thread_interrupted&) { throw; } catch (...) { /* log or whatever */ } or just: try { /* code */ } catch(...) { /* cleanup */ throw; } There are a few such special exceptions that should never be discarded. But in general you should only ever use catch(...) blocks as a way to do try/finally style cleanup (although using RAII types is even better) and always rethrow at the end. It's bad practice to blindly discard exceptions, partly for just this sort of reason but also because it hides bugs and could result in corrupted program state. Try to only catch the specific exception type that you want to suppress (and see if the code has an alternate API that returns the error instead of throwing it).
Le 10/04/2016 16:24, Gaetano Mendola a écrit :
Is there a way for an interruption point to not reset the interruption request flag before throwing?
I have a Class accepting functions to be executed asynchronously this is implemented in terms of boost threads:
T::operator()() { while (true) { foo(); boost::this_thread::interruption_point(); } }
One of those functions performs some operations between a:
try { /*code*/ } catch(...) { }
this basically makes my Class not interruptible indeed that boost::this_thread::interruption_point() is useless if a boost::thread_interrupted has been catched inside the foo.
I have found this: http://lists.boost.org/boost-users/2008/08/39106.php where the guys needs a way to reset it, I need a way to leave the flag on for the entire thread life if an interruption has been requested. Hi,
IIUC what you want is to interrupt the task not the threads, isn't it?? Vicente
participants (3)
-
Gaetano Mendola
-
Gavin Lambert
-
Vicente J. Botet Escriba