[Interest] Heavily Commented Example: Simple Single Frontend with Two Backends

Jan Kundrát jkt at flaska.net
Mon Oct 22 16:07:34 CEST 2012


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/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 259 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121022/90e0156d/attachment.sig>


More information about the Interest mailing list