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