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. How to use memory bits for thread synchronization
Qt 6.11 is out! See what's new in the release blog

How to use memory bits for thread synchronization

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 309 Views 1 Watching
  • 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.
  • tovaxT Offline
    tovaxT Offline
    tovax
    wrote on last edited by tovax
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • tovaxT Offline
      tovaxT Offline
      tovax
      wrote on last edited by tovax
      #2

      Producer:

      forever {
          while (!flag) {
              sleep(1)
          }
          waitCondition.wakeOne();
      }
      
      

      Consumer:

      forever {
          mutex.lock();
          waitCondition.wait(&mutex);
          doSomething();
          mutex.unlock();
      }
      

      Is this correct, please?
      Can I wait for the condition only in the consumer thread?
      Producer:

      eventLoop.exec(); // "flag" will be updated automatically by third-party library.
      

      Consumer:

      forever {
          wait(!flag); // how to wait "flag" true without sleep?
          doSomething();
      }
      
      1 Reply Last reply
      0
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        the simplest way are the std::atomic types, which are part of the c++ standard now. your question and example are heavily weighted toward the language standard and have little to do with Qt primatives.

        The dystopian literature that served as a warning in my youth has become an instruction manual in my elder years.

        1 Reply Last reply
        3

        • Login

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