It depends on what you want to achieve. If you don't care when or if the calls to threadedMethod end, or they drop, then you can just detach stream as soon as you create it; each thread will be destroyed when the method completes. And you should not store the stream in a member variable.
If you don't care, you need to call join for each thread you create (so once for the thread, not once in the destructor). I suspect not.
Do you really need to create a new thread for each call? Creating threads can be expensive, so an alternative would be to use a thread pool and send each threadedMethod call to this. Then the pool could have a MyClass instance lifetime. But perhaps this overflow is for something that happens only once every 30 years.
Alan stokes
source share