Results 1 to 3 of 3

Thread: Terminating Multiple Running Threads?

  1. #1
    Join Date
    May 2010
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Terminating Multiple Running Threads?

    I have a basic web server that accepts an incoming connection and starts a separate QThread to handle the request -

    Qt Code:
    1. void Server::incomingConnection(int socketDescriptor)
    2. {
    3. thread = new ServerThread(socketDescriptor, this);
    4. connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    5. thread->start();
    6. }
    To copy to clipboard, switch view to plain text mode 

    If, for example, I have ten download threads running at the same time and I want to stop them all - immediately - what method should I use to terminate all the threads?
    Last edited by PLan2010; 21st February 2011 at 21:23.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Terminating Multiple Running Threads?

    You can use QThread::terminate() but it isn't pretty.

    Someone with more practical experience will probably explain why you don't need threads to handle multiple requests and why this is a non-problem.

  3. #3
    Join Date
    May 2010
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Terminating Multiple Running Threads?

    Thanks for the reply.

    Think I have a solution ... I store a copy of each new ServerThread pointer in a STL vector then loop through the vector array setting each thread's boolean control variable to "stopped=true" at shutdown. Seems to work.

Similar Threads

  1. FTP Program using multiple Threads
    By neveffects in forum Qt Programming
    Replies: 5
    Last Post: 3rd January 2011, 05:33
  2. Replies: 0
    Last Post: 15th April 2010, 13:44
  3. Multiple threads with one QTcpSocket
    By xenome in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2010, 20:20
  4. Phonon on multiple threads
    By Savignon in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2009, 22:17
  5. Waiting for multiple threads
    By Bebee in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2008, 17:21

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
  •  
Qt is a trademark of The Qt Company.