Solved Android dns resolve crash
-
@sgaist If I had two threads, It would still crash, just for a long time. the request is serial execution .
thank you. -
I run on another phone (Android 9, armv7) , The code work well. The mobile phone that had abnormalities is Android 5.1 armv7. I am not sure whether it depend on mobile phone .
-
@wantfat you do realize that
QThread *thr = new QThread(); thr->start(); while (!QAbstractEventDispatcher::instance(thr)) { thr->wait(1); }
is doing nothing but delay forcefully delay the loop by 1 millisecond?
Also you don't need aQNetworkAccessManager
instance for each get request. QNetworkAccessManager can handle 5 get requests in parallel, IIRC, and the rest is automatically queued -
@j-hilk After call QThread::start the eventDispatcher of thread is null, so must take a sleep wait for eventDispatcher be create, QNetworkAccessManager only one instance for per thread .
-
@wantfat said in Android dns resolve crash:
, QNetworkAccessManager only one instance for per thread
no, from your code, you create 10 QNetworkAccessManager instances and all live inside the main(Gui) thread
-
-
@wantfat have you checked that ? by combining invokeMethod with a lambada the object reference pointer becomes a context pointer. I see no reason, why it should be called from the Thread instance, or I personally don't know, never tried threading in this unusual way.
-
@j-hilk Yes, I have checked it, this is detail info, https://stackoverflow.com/a/21653558
-
The test code work well on Qt 5.12.3, The problematic version is Qt 5.12.4 . I compared two versions of the relevant code
If method __res_init resolve fail dlsym be call, and it return a valid pointer, But it is not a thread safe function. Maybe so.
-
I solved this problem by export thread safe __res_init
#if (QT_VERSION == QT_VERSION_CHECK(5,12,4))
#include "resolv.h"
#include "QMutex"static QMutex mut;
int __res_init(void) {
QMutexLocker lck(&mut);
return res_init();
}#endif
Thanks every one.