多线程:apache 可移植运行时 vs boost::thread?
对于没用过boost的新手来说,哪种方式比较好呢?
当新标准到来时,答案将是显而易见的,但现在我有疑问。 boost 的优点是它更接近未来的标准。
Which way is better for a novice student who has never used boost?
When a new standard arrives, the answer will be obvious, but now I have doubts. Pro for boost is that it's much closer to future standard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Boost 的另一个优点是它使用常见的 C++ 习惯用法来描述、初始化、运行和连接线程(使用 RAII 等习惯用法并允许使用函子和类似的 C++ 专用工具)。
像 APR 这样的低级库依赖于类 C 习惯用法的使用,对于 C++ 开发人员来说,这可能更容易出错(例如函数指针的使用)。
在我看来,Boost::Thread 更容易使用,因为它允许我使用我在代码中其他地方使用的 C++ 习惯用法。对于 APR,我还不如使用 pthreads。
Another pro for Boost is that it uses common C++ idioms for describing, initializing, running, and joining threads (using idioms like RAII and allowing the use of functors and similar C++-specific tools).
Lower-level libraries like APR rely on the use of C-like idioms, which for a C++ developer can prove to be more error-prone (such as the use of function pointers).
In my opinion, Boost::Thread is easier to use because it allows me to use the C++ idioms that I use elsewhere in my code. With APR, I may as well be using pthreads.
由于 boost::thread 可以被视为即将到来的线程标准库实现的草案,因此使用它并可能在几年后用 std::thread 替换它可能是首先要了解的最佳线程库。
As boost::thread can be seen as the draft for the comming standard library implementation of threads, using it and maybe replace it by std::thread in some years might be the best thread library to know first.