diff --git a/src/network/kernel/qhostinfo_unix.cpp b/src/network/kernel/qhostinfo_unix.cpp index b696265ee45..e3f6885924e 100644 --- a/src/network/kernel/qhostinfo_unix.cpp +++ b/src/network/kernel/qhostinfo_unix.cpp @@ -48,6 +48,7 @@ #include "qiodevice.h" #include #include +#include #include #include #include @@ -127,12 +128,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) #endif // Load res_init on demand. - static volatile bool triedResolve = false; - if (!triedResolve) { + static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false); + if (!triedResolve.loadAcquire()) { QMutexLocker locker(QMutexPool::globalInstanceGet(&local_res_init)); - if (!triedResolve) { + if (!triedResolve.load()) { resolveLibrary(); - triedResolve = true; + triedResolve.storeRelease(true); } } diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index 8ace68d9614..5c91d75e5cc 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -121,12 +122,12 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) QWindowsSockInit winSock; // Load res_init on demand. - static volatile bool triedResolve = false; - if (!triedResolve) { + static QBasicAtomicInt triedResolve = Q_BASIC_ATOMIC_INITIALIZER(false); + if (!triedResolve.loadAcquire()) { QMutexLocker locker(QMutexPool::globalInstanceGet(&local_getaddrinfo)); - if (!triedResolve) { + if (!triedResolve.load()) { resolveLibrary(); - triedResolve = true; + triedResolve.storeRelease(true); } }