简体   繁体   中英

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?

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. If not starting a new program, should I use standard library or Boost threads?

Thanks!

If you're not already using boost in your project, there is no reason to use boost::thread in favor of std::thread. That is unless you are using some feature from boost not available in the STL. std::thread is suitable enough for most use cases, and unless compelling arguments are presented, writing standard code is always preferable.

If however you are already using boost in your project, check out if boost::thread offers anything extra compared to std::thread.

请记住,Boost.Thread是一个可移植的库,可以编译各种各样的平台/编译器 - 包括那些std :: thread不可用的平台/编译器。

这实际上取决于你的习惯和喜好。通过提升你有一整套库让你的生活更轻松,但是它们需要安装在你的程序编译的系统上,而std线程你需要的只是一个cpp编译器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM