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


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

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


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

示例1: if


//.........这里部分代码省略.........
                                                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();
                            if (product==3)
                            product1_count++;
                            else if (product==4)
                            product2_count++;
                            else
                            product3_count++;
                            cout<<product1_count<<" of product 3 are generated\n";
                            cout<<product2_count<<" of product 4 are generated\n";
                            cout<<product3_count<<" of product 5 are generated\n";
                        }
                        else// if it is not 1st product
                        {
                            if ((!output_Q.recent(check_product)) || (!output_Q.check_entire(check_product)))
                            {

                                    dead_count++;
                                    cout<<"Deadlock due to recent product is same as new product or different number of products are more than 10 !!!"<<endl;
                                    cout<<"Number of deadlock happened is "<<dead_count<<endl;
                                    while(fix_buffer.size() >=10) //check if there are many of those products
                                    if (pthread_cond_wait (&C1, &M))//producer of the material goes to wait
                                    {
                                        fprintf (stdout, "pthread_cond_wait: producer\n");
                                        exit (-1);
                                    }
                                    //for (int i=0;i<2;i++)
                                    //{

                                    int put_back=require.dequeue();
                                    fix_buffer.enqueue(put_back);
                                    pthread_cond_signal (&C1);
                                    cout<<"Prevent Deadlock put : "<<put_back<<" to buffer"<<endl;
                                    fix_buffer.show();
                                    cout<<"current size of fix_buffer is "<<fix_buffer.size()<<endl;
                                    //}
                            }
                                    /*while(!output_Q.recent(product))//if recent is of same kind then wait
                                    if (pthread_cond_wait (&C2, &M))
                                    {
                                        fprintf (stdout, "pthread_cond_wait: consumer\n");
                                        exit (-1);
                                    }
                                    while(!output_Q.check_entire(product))// wait if the difference are 10
                                    if (pthread_cond_wait (&C2, &M))
                                    {
                                        fprintf (stdout, "pthread_cond_wait: consumer\n");
开发者ID:wjanpong,项目名称:Producer-Consumer,代码行数:67,代码来源:hw2.cpp


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