What’s the best way to delete boost::thread object right after its work is complete?
问题 I create boost::thread object with a new operator and continue without waiting this thread to finish its work: void do_work() { // perform some i/o work } boost::thread *thread = new boost::thread(&do_work); I guess, it’s necessary to delete thread when the work is done. What’s the best way to this without explicitly waiting for thread termination? 回答1: The boost::thread object's lifetime and the native thread's lifetime are unrelated. The boost::thread object can go out of scope at any time.