#include #include #include #include //#define USE_CPP11 #ifdef __GXX_EXPERIMENTAL_CXX0X__ #include #include #include #else #include #include using namespace boost; #endif using namespace std; void executer(mutex& mtx, exception_ptr ex) { for(int i = 0; i < 9999999; i++) { try { lock_guard lck(mtx); rethrow_exception(ex); } catch(...) { current_exception(); // <- run concurrently } } } void test() { exception_ptr ex; try { throw runtime_error("O_o"); } catch(...) { // use current_exception() it's compulsory condition // because only in this case will be used unsafe detail::refcount_ptr // (in current_exception_std_exception_wrapper inherited from exception) ex = current_exception(); } mutex mtx; vector > group; for(int i = 0; i < 10; i++) group.push_back(shared_ptr(new thread(bind(executer, ref(mtx), ex)))); vector >::iterator it = group.begin(); for(; it != group.end(); it++) (*it)->join(); } void version() { #ifdef __GXX_EXPERIMENTAL_CXX0X__ cout << "use c++11 implementation\n"; #else cout << "use boost implementation\n"; #endif } int main() { version(); cout << "Start\n"; test(); cout << "Exit\n"; }