I am trying to add condition_variable to handle threads, but I get a compilation error on this line:
this->cv.wait(lk, []{return this->ready;});
It looks like for the variable this-> ready, 'this' is not in the correct area.
In Java, this can be handled with TestThread.this, is there anything in C ++ doing the same?
void TestThread::Thread_Activity() { std::cout << "Thread started \n"; // Wait until ThreadA() sends data { std::unique_lock<std::mutex> lk(m); this->cv.wait(lk, []{return ready;}); } std::cout << "Thread is processing data\n"; data += " after processing"; // Send data back to ThreadA through the condition variable { // std::lock_guard<std::mutex> lk(m); processed = true; // std::cout << "Thread B signals data processing completed\n"; } }
c ++ scope this condition-variable
Ray
source share