[Interest] QAtomicInt overflow / wrap-around?

Markus Pointner markus.pointner at mooware.at
Thu May 15 22:08:49 CEST 2014


Am 2014-05-15 01:14, schrieb Thiago Macieira:
> On all currently-supported platforms, it will wrap around to INT_MIN and start
> generating negative numbers from there until -1, and then go to zero.

I think about two years ago I had an issue with QAtomicInt on Solaris SPARC, 
where it entered an endless loop after wrapping around. But I just saw that 
Solaris isn't supported anymore in Qt 5.x (and we also gave up support for it), 
so I guess it should be fine.

>> 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?



More information about the Interest mailing list