[Qt-interest] Proper way to terminate QThreads

Thiago Macieira thiago at kde.org
Tue Nov 17 20:27:04 CET 2009


Em Terça-feira 17 Novembro 2009, às 18:36:48, você escreveu:
> bool m_continue = true;
> 
> MyThread::run()
> {
>         while (m_continue)
>         {
>                 readFromSocket();
>                 processData();
>                 ...
>         }
> }
> 

Please remember to make that a volatile bool.

Otherwise the compiler can (correctly) assume that, if it enters the loop 
once, it doesn't ever have to exit that loop.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091117/a580a5dd/attachment.bin 


More information about the Qt-interest-old mailing list