In my code a worker thread emits a signal to gui thread. Signal and Slot are connected via Qt::BlockingQueuedConnection.
When during thecloseEvent application is trying to stop the worker thread and only then finishes the event.
It calls the function of worker thread:
void stop() {
_isFinished = true;
wait();
}
The worker thread in its turn checks _isFinished condition and if it is not set up then emit the signal.
Imaging the following situation
The worker Gui Thread
================= =================
if (!_isFinished) -----------------
----------------- _isFinished = true;
----------------- wait();
emit mySignal(); -----------------
Evidently, both threads would be locked - deadlock.
If I add a mutex then you can find another deadlock situation. When the worker locks the mutex and the gui thread would be blocked. As a result the emitted signal will lock the worker.
How can I deal with this?