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

C++ std::shared_timed_mutex类代码示例

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

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



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

示例1: main

int main()
{
#if _LIBCPP_STD_VER > 11
    {
        m.lock();
        std::vector<std::thread> v;
        for (int i = 0; i < 5; ++i)
            v.push_back(std::thread(f1));
        std::this_thread::sleep_for(ms(250));
        m.unlock();
        for (auto& t : v)
            t.join();
    }
    {
        m.lock();
        std::vector<std::thread> v;
        for (int i = 0; i < 5; ++i)
            v.push_back(std::thread(f2));
        std::this_thread::sleep_for(ms(300));
        m.unlock();
        for (auto& t : v)
            t.join();
    }
#endif  // _LIBCPP_STD_VER > 11
}
开发者ID:0xDEC0DE8,项目名称:ndk,代码行数:25,代码来源:try_lock_shared_for.pass.cpp


示例2: main

int main(int, char**)
{
    {
        m.lock();
        std::vector<std::thread> v;
        for (int i = 0; i < 5; ++i)
            v.push_back(std::thread(f1));
        std::this_thread::sleep_for(WaitTime);
        m.unlock();
        for (auto& t : v)
            t.join();
    }
    {
        m.lock();
        std::vector<std::thread> v;
        for (int i = 0; i < 5; ++i)
            v.push_back(std::thread(f2));
        std::this_thread::sleep_for(WaitTime + Tolerance);
        m.unlock();
        for (auto& t : v)
            t.join();
    }

  return 0;
}
开发者ID:ingowald,项目名称:llvm-project,代码行数:25,代码来源:try_lock_shared_until.pass.cpp


示例3: flushingWork

  void flushingWork()
  {
#if 0
    std::vector< LoggerPtr > loggersList;
    loggersList.reserve(loggers.size());
    mutex.lock_shared();
    for (auto it = loggers.begin(); it != loggers.end(); ++it)
    {
      loggersList.push_back(it->second);
    }
    mutex.unlock_shared();


    for (auto it = loggersList.begin(); it != loggersList.end(); ++it)
    {
      (*it)->flush();
    }
    std::this_thread::yield();
#endif
#if 1
    mutex.lock_shared();
    for (auto it = loggers.begin(); it != loggers.end(); ++it)
    {
      auto logger = it->second;
      logger->flush(); // flushing inside a CS may be not a good idea...
    }
    mutex.unlock_shared();
    std::this_thread::yield();
#endif
}
开发者ID:jjasinski,项目名称:Logger,代码行数:30,代码来源:MultithreadRegistry.hpp


示例4: g

void g()
{
    time_point t0 = Clock::now();
    m.lock_shared();
    time_point t1 = Clock::now();
    m.unlock_shared();
    ns d = t1 - t0;
    assert(d < Tolerance);  // within tolerance
}
开发者ID:markus-oberhumer,项目名称:libcxx,代码行数:9,代码来源:lock_shared.pass.cpp


示例5: f

void f()
{
    time_point t0 = Clock::now();
    m.lock();
    time_point t1 = Clock::now();
    m.unlock();
    ns d = t1 - t0 - ms(250);
    assert(d < ms(50));  // within 50ms
}
开发者ID:0xDEC0DE8,项目名称:ndk,代码行数:9,代码来源:lock.pass.cpp


示例6: f1

void f1()
{
    time_point t0 = Clock::now();
    assert(m.try_lock_for(WaitTime + Tolerance) == true);
    time_point t1 = Clock::now();
    m.unlock();
    ns d = t1 - t0 - WaitTime;
    assert(d < Tolerance);  // within tolerance
}
开发者ID:ingowald,项目名称:llvm-project,代码行数:9,代码来源:try_lock_for.pass.cpp


示例7: f1

void f1()
{
    time_point t0 = Clock::now();
    assert(m.try_lock_for(ms(300)) == true);
    time_point t1 = Clock::now();
    m.unlock();
    ns d = t1 - t0 - ms(250);
    assert(d < ms(50));  // within 50ms
}
开发者ID:Bluerise,项目名称:bitrig,代码行数:9,代码来源:try_lock_for.pass.cpp


示例8: f1

void f1()
{
    time_point t0 = Clock::now();
    assert(m.try_lock_shared_until(Clock::now() + WaitTime + Tolerance) == true);
    time_point t1 = Clock::now();
    m.unlock_shared();
    ns d = t1 - t0 - WaitTime;
    assert(d < Tolerance);  // within 50ms
}
开发者ID:ingowald,项目名称:llvm-project,代码行数:9,代码来源:try_lock_shared_until.pass.cpp


示例9: main

int main()
{
#if _LIBCPP_STD_VER > 11
    m.lock();
    std::thread t(f);
    std::this_thread::sleep_for(ms(250));
    m.unlock();
    t.join();
#endif  // _LIBCPP_STD_VER > 11
}
开发者ID:Bluerise,项目名称:bitrig,代码行数:10,代码来源:try_lock.pass.cpp


示例10: main

int main()
{
    m.lock();
    std::vector<std::thread> v;
    for (int i = 0; i < 5; ++i)
        v.push_back(std::thread(f));
    std::this_thread::sleep_for(ms(250));
    m.unlock();
    for (auto& t : v)
        t.join();
}
开发者ID:32bitmicro,项目名称:riscv-libcxx,代码行数:11,代码来源:try_lock_shared.pass.cpp


示例11: f

void f()
{
    time_point t0 = Clock::now();
    assert(!m.try_lock());
    assert(!m.try_lock());
    assert(!m.try_lock());
    while(!m.try_lock())
        ;
    time_point t1 = Clock::now();
    m.unlock();
    ns d = t1 - t0 - ms(250);
    assert(d < ms(200));  // within 200ms
}
开发者ID:Bluerise,项目名称:bitrig,代码行数:13,代码来源:try_lock.pass.cpp


示例12: f

void f()
{
    time_point t0 = Clock::now();
    assert(!m.try_lock_shared());
    assert(!m.try_lock_shared());
    assert(!m.try_lock_shared());
    while(!m.try_lock_shared())
        ;
    time_point t1 = Clock::now();
    m.unlock_shared();
    ns d = t1 - t0 - ms(250);
    assert(d < Tolerance);  // within tolerance
}
开发者ID:32bitmicro,项目名称:riscv-libcxx,代码行数:13,代码来源:try_lock_shared.pass.cpp


示例13: f2

void f2()
{
    time_point t0 = Clock::now();
    assert(m.try_lock_shared_until(Clock::now() + WaitTime) == false);
    time_point t1 = Clock::now();
    ns d = t1 - t0 - WaitTime;
    assert(d < Tolerance);  // within tolerance
}
开发者ID:ingowald,项目名称:llvm-project,代码行数:8,代码来源:try_lock_shared_until.pass.cpp


示例14: main

int main()
{
    {
        m.lock();
        std::thread t(f1);
        std::this_thread::sleep_for(WaitTime);
        m.unlock();
        t.join();
    }
    {
        m.lock();
        std::thread t(f2);
        std::this_thread::sleep_for(WaitTime + Tolerance);
        m.unlock();
        t.join();
    }
}
开发者ID:markus-oberhumer,项目名称:libcxx,代码行数:17,代码来源:try_lock_until.pass.cpp


示例15: f2

void f2()
{
    time_point t0 = Clock::now();
    assert(m.try_lock_for(ms(250)) == false);
    time_point t1 = Clock::now();
    ns d = t1 - t0 - ms(250);
    assert(d < ms(50));  // within 50ms
}
开发者ID:Bluerise,项目名称:bitrig,代码行数:8,代码来源:try_lock_for.pass.cpp


示例16: main

int main()
{
    m.lock();
    std::vector<std::thread> v;
    for (int i = 0; i < 5; ++i)
        v.push_back(std::thread(f));
    std::this_thread::sleep_for(WaitTime);
    m.unlock();
    for (auto& t : v)
        t.join();
    m.lock_shared();
    for (auto& t : v)
        t = std::thread(g);
    std::thread q(f);
    std::this_thread::sleep_for(WaitTime);
    m.unlock_shared();
    for (auto& t : v)
        t.join();
    q.join();
}
开发者ID:markus-oberhumer,项目名称:libcxx,代码行数:20,代码来源:lock_shared.pass.cpp


示例17: main

int main()
{
#if _LIBCPP_STD_VER > 11
    m.lock();
    std::vector<std::thread> v;
    for (int i = 0; i < 5; ++i)
        v.push_back(std::thread(f));
    std::this_thread::sleep_for(ms(250));
    m.unlock();
    for (auto& t : v)
        t.join();
    m.lock_shared();
    for (auto& t : v)
        t = std::thread(g);
    std::thread q(f);
    std::this_thread::sleep_for(ms(250));
    m.unlock_shared();
    for (auto& t : v)
        t.join();
    q.join();
#endif  // _LIBCPP_STD_VER > 11
}
开发者ID:Bluerise,项目名称:bitrig,代码行数:22,代码来源:mutex.pass.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ std::stack类代码示例发布时间:2022-05-31
下一篇:
C++ std::shared_mutex类代码示例发布时间: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