Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
gcc set_terminate
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64 #include <thread> #include <iostream> #include <map> void handler1() { std::cout << " handler1 "<<std::endl; } void handler2() { std::cout << " handler2 "<<std::endl; } void handler3() { std::cout << " handler3 "<<std::endl; } int main() { std::map<size_t,int> handlerNames; handlerNames[(size_t)std::get_terminate()]=0; handlerNames[(size_t)handler1]=1; handlerNames[(size_t)handler2]=2; handlerNames[(size_t)handler3]=3; using namespace std::chrono_literals; std::cout << "handler at th0 is :" << handlerNames.at((size_t)std::get_terminate()) << std::endl; std::set_terminate(handler1); std::cout << "handler at th0 is :" << handlerNames.at((size_t)std::get_terminate()) << std::endl; auto t1 = std::thread([&handlerNames]() { std::cout << "handler at th1 is :" << handlerNames.at((size_t)std::get_terminate()) << std::endl; std::cout << "t1 started"<<std::endl; std::this_thread::sleep_for(2s); std::cout << "t2 continued"<<std::endl; std::cout << "handler at th1 is :" << handlerNames.at((size_t)std::get_terminate()) << std::endl; std::terminate(); }); std::this_thread::sleep_for(1s); std::set_terminate(handler2); std::cout << "handler at th0 is :" << handlerNames.at((size_t)std::get_terminate()) << std::endl; std::cout << "waiting "<<std::endl; t1.join(); std::cout << "done "<<std::endl; }
run
|
edit
|
history
|
help
0
SetHotel
ListCPP
MemCpyClass
ThreadPool
Silly circular pointer
12532
მატრიცა#2
Graph Theory
LP
pangram