c++ boost 条件变量

程序说明:输入1:启动所有线程;输入0:挂起所以线程

//g++ main.cpp -lboost_system -lboost_thread -lpthread -std=c++11
#include 
#include 
#include 

using namespace std;

boost::condition_variable cond1; //条件变量
boost::condition_variable cond2; //条件变量
boost::mutex bmutex1;  //互斥锁
boost::mutex bmutex2;
static int add = 0;
queue q; //队列
static int input = 0;

void inputQueue()
{
    boost::unique_lock lock(bmutex2);  //加锁
    q.push(add);
    lock.unlock();   //解锁
    cond2.notify_all(); //激活所有线程

    usleep(500*1000);

    cout<<"queue push number is "< lock(bmutex2);
    if(q.empty()){
        cout<<"queue is empty"< lock(bmutex1);
        while(input == 0) {
            cout<<"stop inputQueue thread"< lock(bmutex1);
        while(input == 0) {
            cout<<"stop outputQueue thread"<>input;

        switch (input) {
        case 1:
            cout<<"input is 1"<

 

你可能感兴趣的:(Boost)