百合小说频道,樱木花道结局,洪诗涵
void f(){ std::thread t(my_func); try{ do_some_work(); } catch{ t.join(); throw; } t.join(); }
#include <iostream> #include <thread> using namespace std; class my_thread{ public: explicit my_thread(thread& t_):t(t_){} ~my_thread(){ if(t.joinable()){ // -------->① t.join();// -------->② } } my_thread(my_thread const&) = delete;// -------->③ my_thread& operator=(const my_thread&) = delete; private: thread& t; }; class func{ public: int& data; func(int& d):data(d){} void operator()(){ cout << "thread started@@@@@@@@@@@@@@@@@@@@@@@@@@" << endl; for(unsigned j = 0; j < 100; ++j){ cout << j << endl; } } }; int main(){ int state = 0; func f(state); thread t(f); my_thread mt(t); //do_something_in_current_thread(); }// -------->④
terminate called after throwing an instance of 'std::system_error' what(): invalid argument aborted (core dumped)
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
如何在没有core文件的情况下用dmesg+addr2line定位段错误
用QT制作3D点云显示器——QtDataVisualization
网友评论