• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ fibers::condition_variable_any类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中boost::fibers::condition_variable_any的典型用法代码示例。如果您正苦于以下问题:C++ condition_variable_any类的具体用法?C++ condition_variable_any怎么用?C++ condition_variable_any使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: fn1

void fn1( boost::fibers::mutex & m, boost::fibers::condition_variable_any & cv) {
    m.lock();
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    while (test2 == 0) {
        cv.wait(m);
    }
    BOOST_CHECK(test2 != 0);
    m.unlock();
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:11,代码来源:test_condition_variable_any_dispatch.cpp


示例2: wait_fn

void wait_fn(
	boost::fibers::mutex & mtx,
	boost::fibers::condition_variable_any & cond) {
	mtx.lock();
	cond.wait( mtx);
	++value;
    mtx.unlock();
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:8,代码来源:test_condition_variable_any_dispatch.cpp


示例3: fn5

void fn5( boost::fibers::mutex & m, boost::fibers::condition_variable_any & cv) {
    m.lock();
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now();
    int count=0;
    cv.wait_for(m, ms(250), Pred(test2));
    count++;
    std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
    if (runs == 0) {
        BOOST_CHECK(t1 - t0 < ms(250+1000));
        BOOST_CHECK(test2 != 0);
    } else {
        BOOST_CHECK(t1 - t0 - ms(250) < ms(count*250+2));
        BOOST_CHECK(test2 == 0);
    }
    ++runs;
    m.unlock();
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:20,代码来源:test_condition_variable_any_dispatch.cpp


示例4: fn3

void fn3( boost::fibers::mutex & m, boost::fibers::condition_variable_any & cv) {
    m.lock();
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now();
    std::chrono::steady_clock::time_point t = t0 + ms(250);
    bool r = cv.wait_until(m, t, Pred(test2));
    std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
    if (runs == 0) {
        BOOST_CHECK(t1 - t0 < ms(250));
        BOOST_CHECK(test2 != 0);
        BOOST_CHECK(r);
    } else {
        BOOST_CHECK(t1 - t0 - ms(250) < ms(250+2));
        BOOST_CHECK(test2 == 0);
        BOOST_CHECK(!r);
    }
    ++runs;
    m.unlock();
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:21,代码来源:test_condition_variable_any_dispatch.cpp


示例5: fn2

void fn2( boost::fibers::mutex & m, boost::fibers::condition_variable_any & cv) {
    m.lock();
    BOOST_CHECK(test2 == 0);
    test1 = 1;
    cv.notify_one();
    std::chrono::system_clock::time_point t0 = std::chrono::system_clock::now();
    std::chrono::system_clock::time_point t = t0 + ms(250);
    int count=0;
    while (test2 == 0 && cv.wait_until(m, t) == boost::fibers::cv_status::no_timeout)
        count++;
    std::chrono::system_clock::time_point t1 = std::chrono::system_clock::now();
    if (runs == 0) {
        BOOST_CHECK(t1 - t0 < ms(250));
        BOOST_CHECK(test2 != 0);
    } else {
        BOOST_CHECK(t1 - t0 - ms(250) < ms(count*250+5+1000));
        BOOST_CHECK(test2 == 0);
    }
    ++runs;
    m.unlock();
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:21,代码来源:test_condition_variable_any_dispatch.cpp


示例6: notify_all_fn

void notify_all_fn( boost::fibers::condition_variable_any & cond) {
	cond.notify_all();
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:3,代码来源:test_condition_variable_any_dispatch.cpp


示例7: thread

void thread( unsigned int i, barrier * b) {
    bind_to_processor( i);
    boost::fibers::use_scheduling_algorithm< boost::fibers::algo::shared_work >();
    b->wait();
    lock_type lk( mtx);
    cnd.wait( lk, [](){ return done; });
    BOOST_ASSERT( done);
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:8,代码来源:skynet_shared_join.cpp


示例8: main

int main() {
    try {
        boost::fibers::use_scheduling_algorithm< boost::fibers::algo::shared_work >();
        unsigned int n = std::thread::hardware_concurrency();
        barrier b( n);
        bind_to_processor( n - 1);
        std::size_t size{ 1000000 };
        std::size_t div{ 10 };
        std::vector< std::thread > threads;
        for ( unsigned int i = 1; i < n; ++i) {
            threads.push_back( std::thread( thread, i - 1, & b) );
        };
        allocator_type salloc{ allocator_type::traits_type::page_size() };
        std::uint64_t result{ 0 };
        duration_type duration{ duration_type::zero() };
        channel_type rc{ 2 };
        b.wait();
        time_point_type start{ clock_type::now() };
        skynet( salloc, rc, 0, size, div);
        result = rc.value_pop();
        duration = clock_type::now() - start;
        std::cout << "Result: " << result << " in " << duration.count() / 1000000 << " ms" << std::endl;
        lock_type lk( mtx);
        done = true;
        lk.unlock();
        cnd.notify_all();
        for ( std::thread & t : threads) {
            t.join();
        }
        std::cout << "done." << std::endl;
        return EXIT_SUCCESS;
    } catch ( std::exception const& e) {
        std::cerr << "exception: " << e.what() << std::endl;
    } catch (...) {
        std::cerr << "unhandled exception" << std::endl;
    }
	return EXIT_FAILURE;
}
开发者ID:alexeykuzmin0,项目名称:ThePlatform,代码行数:38,代码来源:skynet_shared_join.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ filesystem::path类代码示例发布时间:2022-05-31
下一篇:
C++ container::vector类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap