
cowwoc wrote:
PS: Is there a more reliable mechanism than atexit() that is guaranteed to support more than 32 hooks?
You could wrap the whole thing in a class, and use a static variable of that class so that its destructor will be called on exit. Something like (not compiled, not tested): class my_thread { private: boost::scoped_ptrboost::thread pt_; bool shutdown_request_; // more per-thread state, if needed void threadproc(); // as before public: my_thread(): shutdown_request_( false ) {} void start() { pt_.reset( new boost::thread( &my_thread::threadproc, this ) ); } ~my_thread() { if( pt_ ) { shutdown_request_ = true; pt_->join(); } } }; // ... static my_thread s_th; int main() { s_th.start(); // ... } // the destructor of s_th should be called here