Is QThread::exit() thread-safe?
-
I understand that QThread::exec() must of course be called from QThread::run(). But is it safe to call exit() from another thread to stop event loop and therefore end default run() execution or exit() should also be called inside that thread only?
-
This is the common way I stop my threads running.
-
It would be safer to use signals and slots to handle this and have the thread itself call exit. You will retain the same functionality but will not have to be concerned on the thread context itself (i.e did you call exit from within a form, etc).
-
One additional idea. In that case the signal slot connection has to be set up with Qt::QueuedConnection so the slot is not being executed in the context of the signalling thread if there was any.