C ++中的多线程...从哪里开始? [英] Multithreading in C++ ... where to start?

查看:112
本文介绍了C ++中的多线程...从哪里开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始学习C ++中的多线程.我也在Java中学习它.在Java中,如果我编写一个使用多线程的程序,它将可以在任何地方使用.但是,在C ++中,多线程是否不依赖于特定于平台的API?如果是这样,那似乎会妨碍可移植性.

如何在C ++中进行多线程处理而又不会引起可移植性问题? boost的 thread 库是否是一个好的解决方案? /p>

作为旁注-怎么可能将多线程实现为一个库?那不是编译器必须要做的事情吗?

解决方案

如果您没有支持 TBB线程构建块感兴趣.

关于Qt:如果仅需要线程支持,那就太过头了.从编译到生成结果,往返时间极慢.这确实是精心设计的思想.但是还没有像boost这样的C ++ 0x线程这样的官方标准.因此,我不会将其作为首选.

I'd like to start learning multithreading in C++. I'm learning it in Java as well. In Java, if I write a program which uses multithreading, it will work anywhere. However in C++, doesn't multithreading rely on platform-specific API's? If so, that would seem to get in the way of portability.

How can I do multithreading in C++ without causing portability issues? Is boost's thread library a good solution?

As a sidenote - how is it even possible to implement multithreading as a library? Isn't that something that has to be done by the compiler?

解决方案

If you do not have a compiler that supports C++0x yet (available with visual studio c++ 2010 for example), use boost threads. (Unless you use a framework that already supports threading, which is not the case - you wouldn't ask the question otherwise -). These boost threads became actually the standard in the brand new C++. Before that time C++ itself was thread unaware.

TBB Threading Building Blocks might also be interesting to you if you want to learn other aspects in parallel programming.

Regarding Qt: if you only want threading support it is complete overkill. It has horribly slow round trip times from compiling to result. It is really well designed thought. But not an official standard like the C++0x threads from boost. Therefore I would not take it as a first choice.

这篇关于C ++中的多线程...从哪里开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆