Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Is QAtomicInteger guaranteed to work on all desktop platforms ?



  • Documentation is quite confusing.

    In one place it says "The API provided by QAtomicInteger is guaranteed to work atomically on all processors. However, since not all processors implement support for every operation provided by QAtomicInteger, it is necessary to expose information about the processor."

    On other place it says "only the 32-bit- and pointer-sized instantiations are guaranteed to work on all platforms. Support for other sizes depends on the compiler and processor architecture the code is being compiled for".

    And then on other place it says:
    "Since many modern architectures allow out-of-order execution and memory ordering, using the correct semantic is necessary to ensure that your application functions properly on all processors."

    Thanks a lot.
    Denis



  • Do you need the operation to be actually atomic or you just want thread safety? AFAIK QAtomicInteger is a wrapper of std::atomic



  • @VRonin I want to achieve thread safe read/write into a bool variable without having to use a mutex. Thanks a lot for prompt reply.



  • @comy said in Is QAtomicInteger guaranteed to work on all desktop platforms ?:

    read/write into a bool variable

    Use std::atomic_bool and forget about the rest



  • @VRonin After looking source code, I found that Qt tried to remove msvc implementation of atomics, but had to revert it back as fallback. I always prefer to use Qt classes, which as you said are wrappers around std::atomic, but msvc/generic fallback implementation makes me think if this is true on my environment. I will double check it. Thanks a lot for your help.


Log in to reply