C++0x thread interruption

All the language specification says that the support isn’t built into the language.
boost::thread::interrupt needs some support from the thread function, too:

When the interrupted thread next executes one of the specified interruption points (or if it is currently blocked whilst executing one)

i.e. when the thread function doesn’t give the caller a chance to interrupt, you are still stuck.

I’m not sure what you mean with “going native” – there is no native support, unless you are spellbound to boost:threads.

Still, I’d use an explicit mechanism. You have to think about having enough interruption points anyway, why not make them explicit? The extra code is usually marginal in my experience, though you may need to change some waits from single-object to multiple-objects, which – depending on your library – may look uglier.


One could also pull the “don’t use exceptions for control flow”, but compared to messing around with threads, this is just a guideline.

Leave a Comment