[Interest] QAtomicInt overflow / wrap-around?

Thiago Macieira thiago.macieira at intel.com
Thu May 15 23:07:07 CEST 2014

Em qui 15 maio 2014, às 22:08:49, Markus Pointner escreveu:
> >> I am aware that for regular non-atomic ints, this would be undefined
> >> behaviour, whereas unsigned ints are defined to wrap around. I would
> >> prefer
> >> the wrap-around behaviour for my atomic value.
> > 
> > Then use QAtomicInteger<unsigned>. That is guaranteed to exist and work on
> > all platforms. If you need a larger address space, use
> > QAtomicInteger<quintptr> or check if Q_ATOMIC_INT64_IS_SUPPORTED is
> > defined.
> But QAtomicInteger is only available in 5.3, right? We are currently
> switching to 5.2, and I saw a QBasicAtomicInteger template there, but it's
> not in the documentation. Can I use that?

QAtomicInteger has been there since 5.0, though it wasn't publicly documented 
until 5.3. It's present whenever Q_ATOMIC_INT32_IS_SUPPORTED is defined. The 
difference is that in 5.3 all implementations define it, so it's present 
everywhere and got documented.

So go ahead and use it. I've got unit tests testing the wrap-around too, 
though they add 42, not 1.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Interest mailing list