当前位置: 首页>>代码示例>>C++>>正文


C++ queue::show方法代码示例

本文整理汇总了C++中queue::show方法的典型用法代码示例。如果您正苦于以下问题:C++ queue::show方法的具体用法?C++ queue::show怎么用?C++ queue::show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在queue的用法示例。


在下文中一共展示了queue::show方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

void *operators(void *threadid)
{
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, operator_thread #%ld!\n", tid);
   queue require;
   queue tools;



   while(true)//for (int i=0; i<10; i++)//change to while(true)
   {


        pthread_mutex_lock(&mutex_pause);
        while (isPaused == 1)
        {
            pthread_cond_wait(&cond_pause, &mutex_pause);
        }
        //else
        //{
        pthread_mutex_unlock(&mutex_pause);
        int rand_time=rand() % 10000;
        usleep(rand_time);



        pthread_mutex_lock(&M);//lock mutex
        //critical section

        if (fix_buffer.size()==0)
        {
            cout<<"Empty"<<endl;
            dead_count++;
            cout<<"Deadlock due to Empty!!!"<<endl;
            cout<<"Number of deadlock happened is "<<dead_count<<endl;
        }
        while(fix_buffer.size()==0)//wait if fixed size buffer is 0
        if (pthread_cond_wait (&C1, &M))
        {
            fprintf (stdout, "pthread_cond_wait: consumer\n");
            exit (-1);
        }

        if (require.size()==0)//get 1st material
        {
            int temp=fix_buffer.dequeue();
            pthread_cond_signal (&C);
            require.enqueue(temp);
            cout<<"get "<<temp<<"by "<<tid<<endl;
            cout<<"require: "<<endl;
            require.show();
        }

        else if (require.size()==1)//get 2nd material
        {

             int temp1=fix_buffer.dequeue();
             pthread_cond_signal(&C);
             if (temp1 != require.front())
             {
                    require.enqueue(temp1);
                    cout<<"get "<<temp1<<"by "<<tid<<endl;
                    cout<<"require: "<<endl;
                    require.show();
                    int check_product=require.check_p();

                    if (output_Q.size()==0) //starting queue no need to check for previous product
                    {
                           int random_tool1;
                           int random_tool2;
                           if(pthread_mutex_trylock(&M1)==0)
                            {
                                       while(tools.size()<2)
                                       {
                                            if (tools.size()==0)
                                            {

                                                random_tool1=rand() % tool_num + 1;
                                                tools.enqueue(random_tool1);
                                                cout<<"get tools"<<random_tool1<<" by operator "<<tid<<endl;
                                                tools.show();
                                            }
                                            else if (tools.size()==1)
                                            {
                                                random_tool1=rand() % tool_num + 1;
                                                if (!(random_tool1==random_tool2))
                                                {
                                                   tools.enqueue(random_tool1);
                                                    cout<<"get tools"<<random_tool1<<" by operator "<<tid<<endl;
                                                    tools.show();
                                                }
                                            }
                                    }
                            }
                            int product=require.dequeue();
                            product=product+require.dequeue();
                            output_Q.enqueue(product);
                            cout<<"output_Q: "<<endl;
                            output_Q.show();
//.........这里部分代码省略.........
开发者ID:wjanpong,项目名称:Producer-Consumer,代码行数:101,代码来源:hw2.cpp


注:本文中的queue::show方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。