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
Forum Updated to NodeBB v4.3 + New Features

How to use memory bits for thread synchronization

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 211 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.
  • T Offline
    T Offline
    tovax
    wrote on 14 Jan 2021, 10:39 last edited by tovax
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • T Offline
      T Offline
      tovax
      wrote on 14 Jan 2021, 14:06 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
      • K Offline
        K Offline
        Kent-Dorfman
        wrote on 15 Jan 2021, 07:45 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.

        1 Reply Last reply
        3

        1/3

        14 Jan 2021, 10:39

        • Login

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