简体   繁体   English

我应该更喜欢std :: thread还是Boost线程?

[英]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.

相关问题 我应该更喜欢Rcpp :: NumericVector而不是std :: vector吗? - Should I prefer Rcpp::NumericVector over std::vector? 可以使用boost :: threads中的std :: this_thread *函数吗? - Is it okay to use std::this_thread* functions from boost::threads? 在boost :: thread中同步STD cout输出,而无需控制线程 - Synchronizing STD cout output in a boost::thread without control over threads 什么时候我应该更喜欢 boost::regex(或 boost::xpressive)而不是 boost::algorithm - When should I prefer boost::regex ( or boost::xpressive) over boost::algorithm 我是否应该相信 std::thread 不是仅通过创建用户线程来实现的? - Should I just believe that std::thread is implemented not by creating user threads only? 我应该在所有地方都使用std ::和boost ::前缀吗? - Should I use std:: and boost:: prefixes everywhere? OpenMP,MPI,POSIX线程,std :: thread,boost :: thread如何关联? - How do OpenMP, MPI, POSIX threads, std::thread, boost::thread correlate? 我什么时候应该使用 std::thread::detach? - When should I use std::thread::detach? 如何使用boost :: thread临时暂停其他线程? - how can I temporarily pause other threads using boost::thread? 我应该使用 std::atomic 还是 std::mutex 来避免线程竞争? - Should I use std::atomic or std::mutex to avoid the thread race?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM