Thread::launch() leaks if still running on exit

As per title, if I launch a thread with Thread::launch() then I exit my application while the thread is still running, then it will leak.

I believe that a better behavior would be to call stopThread() on those LambdaThreads that are still alive when the application exists, to give them a chance to terminate cleanly and thus delete themselves (which AFAIK is a feature unique to them and the actual reason why I’m using them)

In order not to break the current behavior, the new functionality could be implemented adding another Thread::launch() method, whcih takes an additional int parameter which is the argument for the final stopThread() to be called at shutdown, i.e. the number of milliseconds to wait for the thread to exit before forcibly killing it.

The old Thread::launch() method would keep its current behavior, i.e. no stopThread() called at all.

What do you think?

As far as I can see the Thread::launch(std::function) is the only static way to start a new thread. Since that is nowhere owned, it makes perfectly sense to have stopThread triggered automatically.

All other thread incarnations use the virtual run() method, so they cannot call stopThread safely in the destructor (it is too late because the derived class is already destroyed).

I could also see a version where the underlying LambdaThread inherits DeletedAtShutdown and calls stopThread in the destructor. Having the timeout as default argument at the Thread::launch() makes sense IMHO.