#include #include #include using namespace std; boost::mutex mutex_; void perform() { try { boost::this_thread::sleep(boost::posix_time::seconds(100)); } catch(boost::thread_interrupted interrupt) { boost::mutex::scoped_lock lock(mutex_); cerr << "Thread " << boost::this_thread::get_id() << " got interrupted" << endl; throw(interrupt); } catch(...) { boost::mutex::scoped_lock lock(mutex_); cerr << "Thread " << boost::this_thread::get_id() << " caught something else" << endl; } } int main() { boost::thread_group threads; for (int i = 0; i < 2; ++i) { threads.create_thread(perform); } ::sleep(1); threads.interrupt_all(); threads.join_all(); }