[Qt-interest] QAtomicInt and QThread
Thiago Macieira
thiago at kde.org
Mon Jun 27 10:03:42 CEST 2011
Em Monday, 27 de June de 2011, às 09:34:44, Francisco Gonzalez escreveu:
> I know it is not a lock. But some operations on QAtomicInt are
> supposed to be atomic. So perhaps the question would be: is "if (( i
> == 0)" an atomic operation, beeing "i" a QAtomicInt? If it is, we
> could achieve something "similar" to a lock with a QAtomicInt, and
> only similar, as it will block the code of the if condition in all
> threads, while the condition is met. While the part of the code that
> is changing the data is blocked (in any thread) the read operation
> should be safe.
Yes, the reading of a QAtomicInt is atomic, even though it's not documented to
be. We still need to add the operation loadAcquire which is guaranteed to be.
Note that the next operation you do isn't atomic.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110627/c1103fbc/attachment.bin
More information about the Qt-interest-old
mailing list