How to use memory bits for thread synchronization
-
wrote on 14 Jan 2021, 10:39 last edited by tovaxThis post is deleted!
-
wrote on 14 Jan 2021, 14:06 last edited by tovax
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(); }
-
wrote on 15 Jan 2021, 07:45 last edited by
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/3