Results 1 to 3 of 3

Thread: [thread]how to suspend a work thread

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default [thread]how to suspend a work thread

    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

    Qt Code:
    1. Q_D(QThread);
    2. QMutexLocker locker(&d->mutex);
    3.  
    4. if (d->id == GetCurrentThreadId()) {
    5. qWarning("QThread::wait: Thread tried to wait on itself");
    6. return false;
    7. }
    8. if (d->finished || !d->running)
    9. return true;
    10.  
    11. ++d->waiters;
    12. locker.mutex()->unlock();
    13.  
    14. bool ret = false;
    15. switch (WaitForSingleObject(d->handle, time)) {
    16. case WAIT_OBJECT_0:
    17. ret = true;
    18. break;
    19. case WAIT_FAILED:
    20. qErrnoWarning("QThread::wait: Thread wait failure");
    21. break;
    22. case WAIT_ABANDONED:
    23. case WAIT_TIMEOUT:
    24. default:
    25. break;
    26. }
    27.  
    28. locker.mutex()->lock();
    29. --d->waiters;
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 27th July 2008 at 08:47. Reason: missing [code] tags

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  2. Replies: 10
    Last Post: 20th March 2007, 22:19
  3. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.