While using boost::threads I have come across this interruption problem. When I do a boost::thread_interrupt from thread A on thread B, while B has interrupts disabled (boost::this_thread::disable_interrupts di), the interrupt seems to be lost. That is to say, that if I put a boost::thread::interruption_point() after interruption has been enabled, it does not throw the boost::thread_interrupted exception.
Is this the expected behavior or am I doing something wrong?
Thanks
Nothing in the documentation says that interruptions are re-triggered when thread B re-enables interruptions. I've tried a simple test program and can confirm the behaviour you describe.
After re-enabling interruptions, you can check
this_thread::interruption_requested()
to see if there was an interruption requested while interruptions were disabled. If an interruption was indeed requested, you can throw athread_interrupted
exception yourself.Here's a working program that demonstrates this:
Hope this helps.