Terminating Multiple Running Threads?
I have a basic web server that accepts an incoming connection and starts a separate QThread to handle the request -
Code:
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?
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.
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. :p