c++ - How to use boost::thread::at_thread_exit or call a function when thread is done -
this minimal code illustrate need. doesn't work, because (as rightly error message says when compiling) at_thread_exit not member of boost::thread. know related namespace this_thread, i've been going through documentation @ boost page, cannot follow how use at_thread_exit. haven't been able find simple example of how use using google.
#include <boost/thread.hpp> #include <iostream> class a{ public: void callme(){ int = 1; } void runthread() { boost::thread td(&a::callme,this); td.at_thread_exit(&a::done,this); td.join(); } void done() { std::cout << "i done!!!\n"; } }; int main(int argc, char **argv) { *a = new a(); a->runthread(); delete a; return exit_success; }
boost::thread td([this]{ callme(); done(); });
at_thread_exit
works within same thread; require sychronization otherwise, , make every thread pay when threads use it.
Comments
Post a Comment