From 8b0fd78caa8e257757d3eb84732e38cf735b2136 Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Thu, 10 Apr 2014 17:12:20 +0300 Subject: WinRT: Don't use the native thread handle for waiting There is no guarantee that the handle from std::thread will be valid when a wait is made. Instead, simply use an elapsed timer and check if the thread is finished. This prevents an exception from being thrown when a bad handle is encountered. Task-number: QTBUG-31397 Change-Id: Ie2a7e6cbfbb27bf1baff779322670d85e92e10dd Reviewed-by: Oliver Wolff --- src/corelib/thread/qthread_win.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src/corelib/thread/qthread_win.cpp') diff --git a/src/corelib/thread/qthread_win.cpp b/src/corelib/thread/qthread_win.cpp index a12636778e..bdc3463b9f 100644 --- a/src/corelib/thread/qthread_win.cpp +++ b/src/corelib/thread/qthread_win.cpp @@ -63,6 +63,7 @@ #include #ifdef Q_OS_WINRT +#include #include #endif @@ -680,21 +681,11 @@ bool QThread::wait(unsigned long time) break; } #else // !Q_OS_WINRT - if (d->handle->joinable()) { - HANDLE handle = d->handle->native_handle(); - switch (WaitForSingleObjectEx(handle, time, FALSE)) { - case WAIT_OBJECT_0: - ret = true; - d->handle->join(); - break; - case WAIT_FAILED: - qErrnoWarning("QThread::wait: WaitForSingleObjectEx() failed"); - break; - case WAIT_ABANDONED: - case WAIT_TIMEOUT: - default: - break; - } + if (!d->finished) { + QElapsedTimer timer; + timer.start(); + while (timer.elapsed() < time && !d->finished) + yieldCurrentThread(); } #endif // Q_OS_WINRT -- cgit v1.2.3