消费者生产者问题

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
int main(int argc,char **argv){
    queue buffer;
    mutex m;
    condition_variable cond_var;
    int num;

    thread producer([&](){
       while(1){
           this_thread::sleep_for(chrono::seconds(1));

           unique_lock lock(m);

           num++;
           cout<<"produucing"< lock(m);

            if(buffer.empty())
                cond_var.wait(lock);

            cout<<"consuming"<

你可能感兴趣的:(消费者生产者问题)