Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is QAtomicInteger guaranteed to work on all desktop platforms ?
Qt 6.11 is out! See what's new in the release blog

Is QAtomicInteger guaranteed to work on all desktop platforms ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    comy
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 1 Reply Last reply
      2
      • VRoninV VRonin

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

        C Offline
        C Offline
        comy
        wrote on last edited by
        #3

        @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.

        VRoninV 1 Reply Last reply
        0
        • C comy

          @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.

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @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

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          C 1 Reply Last reply
          2
          • VRoninV VRonin

            @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

            C Offline
            C Offline
            comy
            wrote on last edited by comy
            #5

            @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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved