On 10/22/12 14:12, Till Oliver Knoll wrote:
> So the net effect is that the "worker thread" does "one loop too much"
> - but /eventually/ it will see that m_continue has been set to 'false'
> and will terminate. And that is exactly what we want and hence "good
> enough" (no need for protecting the member m_continue with a mutex!).

Hi Till,
you don't need a mutex, but you need a guarantee that the compiler will
recognize that you use that variable for inter-thread synchronization.
Volatile does not do that. Qt's QAtomicInt or C++11's std::atomic_bool
or std::atomic_flag will work fine.

A good read of what volatile actually is for and how it differs from
these atomic variables is available from the links I posted in my other
reply to this thread. A great source for information are also various
articles speaking about the "memory model" -- if you're interested and
have some time to spare, I'd suggest reading them. It was definitely fun
for me.

With kind regards
Jan

-- 
Trojita, a fast e-mail client -- http://trojita.flaska.net/

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to