It depends on what kind of behavior you are looking for.
If you want to delete an object and stop its stream object, and then delete its stream object, then you should have a stop flag that your stream checks from time to time. In the destructor, you set the stop flag, and then call join() in your thread. Once he returns, you can safely remove the pointer.
If, on the other hand, you want to delete the object and continue the thread until it ends, you will need a smarter mechanism, for example, at the end of your thread function, placing a callback in the main thread of your application that calls join() in your thread and then delete it. For this, of course, you need a pointer to your stream object in your stream function.
EDIT In the case of boost::thread it just detaches in its destructor, so for the second option, you can safely remove it when you're done. It is important to note, however, that this will not work with the std::thread destructor, which will then terminate your program. But then you can also manually call detach() and then delete . So you really need to look at the API you are using.
source share