[C++] pthread and std::thread区别

So in summary:

  • Use pthread if you need maximum portability and control. 更加底层一些?
  • Use std::thread if you want an easier to use API and tighter integration with C++. 是对POSIX线程(即pthread)的一个高级封装,提供了更加易用和跨平台的线程支持
  • For most C++ programs, I would recommend starting with std::thread. Only drop down to pthreads if you need something std::thread cannot provide.

pthread

Pros:

  • Portable (POSIX standard):POSIX标准是IEEE为在各种UNIX操作系统上运行的软件定义的一系列API标准的总称,定义了Unix系列操作系统对应用的接口规范
  • Low level API gives you a lot of control
  • Can be used in C programs as well as C++
    Cons:
  • Low level API can be cumbersome(笨重) to use
  • Lacks some convenient features of std::thread like return values, exceptions, etc. 重要不足

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值