コード例 #1
0
ファイル: Concept05.cpp プロジェクト: KunjeshBaghel/CPP01
// this function keep checking if deque is empty, if it is not then it will pops out the data and 
// print it.
void function02()
{
    int data = 0;
    while(data != 1)
    {
        unique_lock<mutex> locker(mu);
        cond.wait(locker, [](){return !q.empty();}); // passing lamda expression
        /*
        We can solve the problem which we have discussed in concept03. by passing second parameter.
        in wait function. which is a lamda expression.
        
        so according to that lamda expression if the queue is empty then it will go back to sleep 
        again. If queue is not empty then it will go ahead and pop out the data.
        */
        data = q.back();
        q.pop_bacl();
        locker.unlock();
        cout << "t2 got a value for t1 " << data << endl;
    }
}