PDA

View Full Version : Terminating Multiple Running Threads?



PLan2010
21st February 2011, 21:19
I have a basic web server that accepts an incoming connection and starts a separate QThread to handle the request -



void Server::incomingConnection(int socketDescriptor)
{
thread = new ServerThread(socketDescriptor, this);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
}



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?

ChrisW67
21st February 2011, 21:36
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.

PLan2010
21st February 2011, 23:15
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. :p