[Thread] Resetting interruption request
Hello, I'm afraid this is a frequently asked question, but my attempts at searching have not been successful. My question is whether there is a smarter way to reset the interruption request (if any) than this: try { boost::this_thread::interruption_point(); } catch (boost::thread_interrupted&) { // ignore } Which I find a little messy for what I want to achieve. I'm using version 1.35.0. Best regards, Christian Larsen
Christian Larsen
I'm afraid this is a frequently asked question, but my attempts at searching have not been successful. My question is whether there is a smarter way to reset the interruption request (if any) than this:
try { boost::this_thread::interruption_point(); } catch (boost::thread_interrupted&) { // ignore }
Which I find a little messy for what I want to achieve. I'm using version 1.35.0.
That's essentially the only way to do it, but if interruption is disabled, even that won't work. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Anthony Williams skrev:
Christian Larsen
writes: [snip] My question is whether there is a smarter way to reset the interruption request (if any) than this:
try { boost::this_thread::interruption_point(); } catch (boost::thread_interrupted&) { // ignore } [snip]
That's essentially the only way to do it, but if interruption is disabled, even that won't work.
Ok, thanks for the reply. Would there be any chance that a function for this would be added? I mean, it doesn't feel right to throw and catch an exception for controlling program flow (haven't benchmarked, but it has to be more expensive than flipping a flag). Couldn't a reset functionality easily be added? In the specific situation where I'm using this, I have a thread which sleeps in the background, but wakes up when it's assigned a task. It runs the task to completion (tasks should be interruptible using thread::interrupt) and then falls back to sleep waiting for another task. What I need to make sure is that a call to interrupt while the the thread is sleeping waiting on a condition variable (at this point interruption _is_ disabled) is forgotten once a new task has arrived, such that the new task (interruptible) will run regardless of earlier interruptions. Best regards, Christian
Christian Larsen
Anthony Williams skrev:
Christian Larsen
writes: [snip] My question is whether there is a smarter way to reset the interruption request (if any) than this:
try { boost::this_thread::interruption_point(); } catch (boost::thread_interrupted&) { // ignore } [snip]
That's essentially the only way to do it, but if interruption is disabled, even that won't work.
Ok, thanks for the reply.
Would there be any chance that a function for this would be added? I mean, it doesn't feel right to throw and catch an exception for controlling program flow (haven't benchmarked, but it has to be more expensive than flipping a flag). Couldn't a reset functionality easily be added?
Yes, it could be added. I've put it on my list. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL
Anthony Williams skrev: [snip]
That's essentially the only way to do it, but if interruption is disabled, even that won't work. Ok, thanks for the reply.
Would there be any chance that a function for this would be added? I mean, it doesn't feel right to throw and catch an exception for controlling program flow (haven't benchmarked, but it has to be more expensive than flipping a flag). Couldn't a reset functionality easily be added?
Yes, it could be added. I've put it on my list.
Cool, thanks. :) Best regards, Christian
participants (2)
-
Anthony Williams
-
Christian Larsen