[Qt-interest] Qthread takes a long time to stop
Jeroen De Wachter
jeroen.dewachter at barco.com
Mon Jun 21 12:13:10 CEST 2010
Hi Sarvesh,
Do you know if the delay is in processing the message or getting the
message?
Because if your getmessage() function is a blocking call and it waits
for a message from the server (or for a timeout to occur), that may be a
lot more important than the overhead of processing the message.
Kind regards,
Jeroen
Sarvesh Saran wrote:
>
> Hi,
>
> I have a helper thread derived from QThread which runs in a forever
> loop. Inside the loop it reads messages from a server , does some
> processing of the messages and send the message to the Main GUI thread.
>
> So the helper thread looks something like:
>
> Helperthread::run()
>
> {
>
> while(allowedToRun())
>
> {
>
> QString msg;
>
> getmessage(&msg); //read a message from the server
>
> processMessage(msg);
>
> }
>
> }
>
> Helperthread::processMessage()
>
> {
>
> //lots of case statements here….(to identify message types) and lots
> of message processing
>
> }
>
> //this is a public slot called by the main GUI thread
>
> Helperthread::setAllowedToRun()
>
> {
>
> //set the flag to false;
>
> }
>
> My problem is that when the main window gets a close signal, it sets
> the flag to false and has to wait for a long time for the helper
> thread to finish.
>
> i.e in the main window on close :
>
> MainWindow::closeEvent()
>
> {
>
> helperthread->setAllowedToRun(false);
>
> helperthread->wait(); //this takes a long time because the helper
> thread’s processMessage is quiet big and takes a long while to return.
>
> }
>
> Is there a way I can speed this up so that my main window does not
> have to wait for a long time for the helper thread to exit ?
>
> Thanks,
>
> Sarvesh
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.
More information about the Qt-interest-old
mailing list