[Qt-interest] Fwd: QAtomicInt and QThread
Thiago Macieira
thiago at kde.org
Fri Jun 24 17:52:27 CEST 2011
Em Friday, 24 de June de 2011, às 18:42:26, Mandeep Sandhu escreveu:
> >> 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.
>
> For your specific case of reading/writing integer values, it might
> suffice. Though I've never used it myself so maybe someone else on the
> list can confirm?
It's not.
Reading a 64-bit integer on a 32-bit platform is not atomic, much less thread-
safe.
The entire example is thread-unsafe and will produce weird values.
--
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/20110624/fb11db42/attachment.bin
More information about the Qt-interest-old
mailing list