[Qt-interest] Proper way to terminate QThreads
Mihail Naydenov
mlists at ymail.com
Wed Nov 18 13:12:42 CET 2009
----- Original Message ----
> From: Thiago Macieira <thiago at kde.org>
> To: qt-interest at trolltech.com
> Sent: Tue, November 17, 2009 9:27:04 PM
> Subject: Re: [Qt-interest] Proper way to terminate QThreads
>
> 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.
While on the subject, I was wondering why does the famous Mandelbrot example neither define its "abort" and "restart" variable as volatile, nor
locks the mutex when accessing them (checking if set in the loop)?
Is it save and why?
Just curious, thanks
MihailNaydenov
>
> --
> 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
More information about the Qt-interest-old
mailing list