void nuke_ms::clientnode::catchThread(boost::thread& thread, unsigned threadwait_ms) { // a thread id that compares equal to "not-a-thread" boost::thread::id not_a_thread; try { // give the thread a few seconds time to join thread.timed_join(boost::posix_time::millisec(threadwait_ms)); } catch(...) {} // if the thread finished, return. otherwise try to kill the thread if (thread.get_id() == not_a_thread) return; thread.interrupt(); // if it is still running, let it go if (thread.get_id() == not_a_thread) return; thread.detach(); }
~download_thread_control() { if (thread.joinable()) thread.detach(); }