[Qt-interest] Fwd: QAtomicInt and QThread

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Fri Jun 24 13:49:45 CEST 2011


>> I see some manipulation of a non-atomic 64-bit int inside a loop and reading
>> of the same 64-bit integer from another function. Since you didn't try to use
>> the atomic there, I don't suppose you care that this is non-atomic and can
>> produce weird results.
> Does the read() function lives in the same thread as the loop function

>From what I see, you're invoking the read() SLOT as a
DirectConnection. This means that the slot will be invoked in the
context of the main thread, NOT in the context of the other thread
that you start.

> in the example?, and then, is it safe to read the m_count using the
> read() slot from another thread
> If not is it possible to use QAtomicInt to block the part of the code
> that modifies the data?

What you need for protecting the atomicity of read/write ops between
threads is mutex. eg: you use QMutex from serializing access to the
shared data.

HTH,
-mandeep

> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>



More information about the Qt-interest-old mailing list