C++Boost库学习之thread库(一)

本文深入探讨了C++ Boost库中的thread库,包括类thread的定义和使用,命名空间this_thread的功能及示例,以及类thread_group的详细解释与应用实例。通过这些内容,读者将能更好地理解和掌握Boost库中的线程管理。
摘要由CSDN通过智能技术生成

目录

1.thread库概述
2.类thread
  ①类定义
  ②使用例子
3.命名空间this_thread
  ①空间内定义
  ②使用例子
4.类thread_group
  ①类定义
  ②使用例子

1.thread库 ^

  Boost.Thread允许在可移植C ++代码中使用多个执行线程和共享数据。它提供了用于管理线程本身的类和函数,以及用于在线程之间同步数据或提供特定于各个线程的数据的单独副本的其他类。

#include <boost/thread/thread.hpp>

namespace boost
{
  class thread;
  void swap(thread& lhs,thread& rhs) noexcept;

  namespace this_thread
  {
    thread::id get_id() noexcept;
    template<typename TimeDuration>
    void yield() noexcept;
    template <class Clock, class Duration>
    void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
    template <class Rep, class Period>
    void sleep_for(const chrono::duration<Rep, Period>& rel_time);
    namespace no_interruption_point  // 扩展
    {
        template <class Clock, class Duration>
        void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
        template <class Rep, class Period>
        void sleep_for(const chrono::duration<Rep, Period>& rel_time);
    }
    template<typename Callable>
    void at_thread_exit(Callable func); // 扩展

    void interruption_point(); // 扩展
    bool interruption_requested() noexcept; // 扩展
    bool interruption_enabled() noexcept; // 扩展
    class disable_interruption; // 扩展
    class restore_interruption; // 扩展

  #if defined BOOST_THREAD_USES_DATETIME
    template <TimeDuration>
    void sleep(TimeDuration const& rel_time);  // 扩展
    void sleep(system_time const& abs_time); // 扩展
  #endif
  }
  class thread_group; // 扩展

}

2.类thread ^

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值