C++多线程教程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/279009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:17:31  来源:igfitidea点击:

C++ multithreading tutorial

c++multithreading

提问by lmsasu

Is there a good tutorial on working with (programming) threads in Visual Studio 2005? Not MFCrelated, just native C++ (no .NET).

是否有关于在 Visual Studio 2005 中使用(编程)线程的好教程?没有MFC相关,只是原生C ++(无.NET)。

回答by Tom Leys

Instead of using Win32 threads directly, I'd consider using a thread wrapper such as Boost threads. These are cross platform so porting your application later will be easier.

我不会直接使用 Win32 线程,而是考虑使用线程包装器,例如Boost threads。这些是跨平台的,因此以后移植您的应用程序会更容易。

回答by sergtk

You may take a look at the following OpenMP tutorials. This doesn't concern all concepts of multithreading in VC++, but OpenMP only, which VC++ supports. OpenMP is easy to use in some simple cases of multithreading, for instance independent iterations in loop, independent blocks of code which can be executed concurrently. Although OpenMP is not so flexible in comparison with other approaches but it is very easy to use.

您可以查看以下 OpenMP 教程。这并不涉及 VC++ 中多线程的所有概念,而仅涉及 VC++ 支持的 OpenMP。OpenMP 在一些简单的多线程情况下很容易使用,例如循环中的独立迭代、可以并发执行的独立代码块。尽管与其他方法相比,OpenMP 不是那么灵活,但它非常易于使用。

To enable OpenMP you need to switch it on in the project properties, "C/C++/Language/OpenMP Support".

要启用 OpenMP,您需要在项目属性“C/C++/Language/OpenMP Support”中将其打开。

回答by Tim

Win32 Multithreaded Programming

Win32 多线程编程

Also try some of the free undergraduate podcasts on operating systems. You can find theoretical discussions on locking, multithreading, etc. (the one I know of is from Berkeleyand is based on Java, but it is still relevant).

还可以尝试一些关于操作系统的免费本科播客。您可以找到关于锁定、多线程等的理论讨论(我所知道的那个来自伯克利并且基于 Java,但它仍然是相关的)。