[Qt-interest] Fwd: QAtomicInt and QThread

Francisco Gonzalez gzmorell at gmail.com
Fri Jun 24 15:03:22 CEST 2011


> 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.
Thanks, I do not know that. That explains the behavior. Since the
thread event loop is blocked by the loop function.
>
>> 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.
Is it not enough to use a QAtomicInt? From the docs the "=" and "=="
operators seems to be atomic on QAtomicInt. So that way at least the
last example should work.
>
> 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