本文整理汇总了C++中boost::lockfree::queue::is_lock_free方法的典型用法代码示例。如果您正苦于以下问题:C++ queue::is_lock_free方法的具体用法?C++ queue::is_lock_free怎么用?C++ queue::is_lock_free使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::lockfree::queue
的用法示例。
在下文中一共展示了queue::is_lock_free方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
using namespace std;
cout << "boost::lockfree::queue is ";
if (!queue.is_lock_free())
cout << "not ";
cout << "lockfree" << endl;
boost::chrono::steady_clock::time_point start = boost::chrono::steady_clock::now();
boost::thread_group producer_threads, consumer_threads;
for (int i = 0; i != producer_thread_count; ++i)
producer_threads.create_thread(producer);
for (int i = 0; i != consumer_thread_count; ++i)
consumer_threads.create_thread(consumer);
producer_threads.join_all();
done = true;
consumer_threads.join_all();
boost::chrono::duration<double> sec = boost::chrono::steady_clock::now() - start;
cout << "f() took " << sec.count() << " seconds\n";
cout << "produced " << producer_count << " objects." << endl;
cout << "consumed " << consumer_count << " objects." << endl;
}
示例2: main
int main()
{
cout << "boost::lockfree::queue is ";
if (!queue.is_lock_free())
cout << "not ";
cout << "lockfree" << endl;
//boost::thread 线程群管理器
boost::thread_group producer_group, consumer_group;
//创建生产者
for(int i=0; i<producer_thread_count; i++)
{
producer_group.create_thread(producer);
}
//创建消费者
for(int i=0; i<consumer_thread_count; i++)
{
consumer_group.create_thread(consumer);
}
//等待生产者生产完毕
producer_group.join_all();
done = true;
cout<<"done"<<endl;
//等待消费者消费结束
consumer_group.join_all();
//输出生产和消费数量
cout<<endl;
cout << "produced " << p_count << " objects." << endl;
cout << "consumed " << c_count << " objects." << endl;
return 0;
}
示例3: main
int main(int argc, char* argv[])
{
using namespace std;
cout << "boost::lockfree::queue is ";
if (!queue.is_lock_free())
cout << "not ";
cout << "lockfree" << endl;
boost::thread_group producer_threads, consumer_threads;
for (int i = 0; i != producer_thread_count; ++i)
producer_threads.create_thread(producer);
for (int i = 0; i != consumer_thread_count; ++i)
consumer_threads.create_thread(consumer);
producer_threads.join_all();
done = true;
consumer_threads.join_all();
cout << "produced " << producer_count << " objects." << endl;
cout << "consumed " << consumer_count << " objects." << endl;
}