I want to suspend a work thread, so i tried to call wait(ms). But it never worked.
When I called wait() in the MsgThread derived from QThread, it entered into Line02/03, then returned from wait(). When I called wait(ms) in some function of a class derived from QDialog, then it reached Line 10, and then just jumped to Line22 after ms; however, the working thread did not been suspended. So wait() did not suspend the desired thread, it worked to the GUI thread!
So what can I do to get the work thread to be suspended?
thanks a lot!
By the way, the program has only one workthread
if (d->id == GetCurrentThreadId()) {
qWarning("QThread::wait: Thread tried to wait on itself");
return false;
}
if (d->finished || !d->running)
return true;
++d->waiters;
locker.mutex()->unlock();
bool ret = false;
switch (WaitForSingleObject(d->handle, time)) {
case WAIT_OBJECT_0:
ret = true;
break;
case WAIT_FAILED:
qErrnoWarning("QThread::wait: Thread wait failure");
break;
case WAIT_ABANDONED:
case WAIT_TIMEOUT:
default:
break;
}
locker.mutex()->lock();
--d->waiters;
Q_D(QThread);
QMutexLocker locker(&d->mutex);
if (d->id == GetCurrentThreadId()) {
qWarning("QThread::wait: Thread tried to wait on itself");
return false;
}
if (d->finished || !d->running)
return true;
++d->waiters;
locker.mutex()->unlock();
bool ret = false;
switch (WaitForSingleObject(d->handle, time)) {
case WAIT_OBJECT_0:
ret = true;
break;
case WAIT_FAILED:
qErrnoWarning("QThread::wait: Thread wait failure");
break;
case WAIT_ABANDONED:
case WAIT_TIMEOUT:
default:
break;
}
locker.mutex()->lock();
--d->waiters;
To copy to clipboard, switch view to plain text mode
Bookmarks