Beispiel #1
0
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;
}
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;
}
Beispiel #3
0
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;
}