[英]Should I prefer std::thread or Boost threads?
I'm new to C++ (coming from C#) writing a multi-threaded C++ application and wondering what is better to use: std::thread
or its Boost counterpart? 我是C ++(来自C#)的新手,编写了一个多线程的C ++应用程序,并想知道什么是更好的使用:
std::thread
或它的Boost对应物?
I saw the following discussion in another Stack Overflow post, but still do not have the complete picture of why should I choose one over the other. 我在另一个Stack Overflow帖子中看到了以下讨论 ,但仍然没有完整的图片说明我为什么要选择一个而不是另一个。 If not starting a new program, should I use standard library or Boost threads?
如果没有启动新程序,我应该使用标准库还是Boost线程?
Thanks! 谢谢!
If you're not already using boost in your project, there is no reason to use boost::thread in favor of std::thread. 如果您尚未在项目中使用boost,则没有理由使用boost :: thread来支持std :: thread。 That is unless you are using some feature from boost not available in the STL.
这是除非你使用STL中没有提供的某些功能。 std::thread is suitable enough for most use cases, and unless compelling arguments are presented, writing standard code is always preferable.
std :: thread适用于大多数用例,除非提供令人信服的参数,否则编写标准代码总是更可取的。
If however you are already using boost in your project, check out if boost::thread offers anything extra compared to std::thread. 但是,如果您已经在项目中使用了boost,请检查boost :: thread是否提供了与std :: thread相比更多的东西。
请记住,Boost.Thread是一个可移植的库,可以编译各种各样的平台/编译器 - 包括那些std :: thread不可用的平台/编译器。
这实际上取决于你的习惯和喜好。通过提升你有一整套库让你的生活更轻松,但是它们需要安装在你的程序编译的系统上,而std线程你需要的只是一个cpp编译器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.