在哪种操作系统上,线程编程足以利用多核?

发布于 2024-07-13 07:18:34 字数 109 浏览 7 评论 0 原文

我想利用我的多线程编程技能(我有技能),但我意识到这还不够。 如果操作系统没有意识到这种潜力,我的线程可能仍然会竞争同一个核心。 我可以在英特尔至强架构上使用什么操作系统/编译器/库组合来线程到内核?

I would like to use my multi-threading programming skills (I got skills), but I realize that that is not enough. My threads may still compete for the same core if the operating system is not aware of the potential. What OS/compiler/library combination can I use on Intel Xeon architecture to thread to the cores?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

通知家属抬走 2024-07-20 07:18:35

大多数现代操作系统都为多处理做好了准备。 因此,它们已经为多核做好了准备。 然而,调度程序负责将线程分配给核心。
FreeBSD 是最高效的多核和多处理操作系统之一。
然而,并非每个操作系统都能够将线程调度到不同的内核。 例如,旧的 Windows 98 不能使用多个内核。 此外,许多操作系统对最大内核数都有限制。

我在 Stackoverflow 上读到了一些用户谈论 Packt Publishing 的新书的帖子,并且我在 Packt Publishing 网页中找到了以下文章:

http://www.packtpub.com/article/simplifying-parallelism-complexity-c-sharp

我读过 Windows 并发编程,乔·达菲的书。 现在,我正在等待 Hillar 的书“C# 2008 和 2005 线程编程” - http: //www.amazon.com/2008-2005-Threaded-Programming-Beginners/dp/1847197108/ref=pd_rhf_p_t_2

Most modern operating systems are prepared for multiprocessing. Hence, they are prepared for multicore. However, the scheduler is the responsible for distributing the threads to the cores.
One of the most efficient multicore and multiprocessing OS is FreeBSD.
However, not every OS is capable of scheduling threads to different cores. For example, the old Windows 98 does not work with more than one core. Besides, many OS have restrictions on the maximum number of cores.

I've read some posts in Stackoverflow from a user talking about a new book from Packt Publishing and I've found the following article in Packt Publishing web page:

http://www.packtpub.com/article/simplifying-parallelism-complexity-c-sharp

I've read Concurrent Programming with Windows, Joe Duffy's book. Now, I am waiting for "C# 2008 and 2005 Threaded Programming", Hillar's book - http://www.amazon.com/2008-2005-Threaded-Programming-Beginners/dp/1847197108/ref=pd_rhf_p_t_2

一梦等七年七年为一梦 2024-07-20 07:18:35

在另一篇文章中,我推荐了一本新书。
如果您正在寻找深入的答案,我建议您阅读 Gaston C. Hillar - Packt Publishing 所著的《C# 2008 和 2005 线程编程》的前两章。
五天前我买这本书之前并不知道你问题的答案。 现在,我能够看到我的 Core 2 Quad Q6700 使用 4 个并发线程在 C# 中达到 98% CPU 使用率!
这比我想象的要容易。 如果你有多线程知识,那对你来说会更容易。 同时使用多个内核所获得的结果给我留下了深刻的印象。 我向那些有兴趣使用 C# 进行多核或线程编程的人推荐这本书。
我不是 C++ 程序员。 因此,我需要一本 C# 初学者书籍来利用线程来利用多核。

In another post, I recommended a new book.
If you are looking for a deep answerd, I do recommend you to read the first two chapters of "C# 2008 and 2005 threaded programming", by Gaston C. Hillar - Packt Publishing.
I didn't know the answer to your question before I bought the book 5 days ago. Now, I am capable of watching my Core 2 Quad Q6700 reach 98% CPU usage programming in C# using 4 concurrent threads!
It is easier than I thought. If you have multithreaded knowledge, it will be even easier for you. I am impressed with the results you can achieve using many cores at the same time. I recommend the book to those who are interested in beginning with multicore or threaded programming using C#.
I am not a C++ programmer. For this reason, I needed a C# beginner's book to exploit multicore using threads.

向日葵 2024-07-20 07:18:34

所有现代操作系统都将线程分布在所有可用内核上; 但有几种语言或库可以防止这种情况发生。 最常见的问题是:

  • 绿色线程。 当多个 CPU 很少且操作系统优化不够时,它曾经具有性能优势。 有几个 Java VM 吹嘘此为一项功能,后来转向 M:N 方案,我认为现在到处都是 N:N。

  • GIL:全局解释器锁。 一些脚本语言在解释器循环深处有很多全局状态,因此有一个大(互斥)锁来确保一致性; 但这会阻止同一“空间”的两个线程同时运行。 至少Python和Lua有这个问题。 在这些情况下,最好使用多个进程而不是多个线程。

另外,最好记住,大多数 CPU 密集型应用程序的最大瓶颈是 RAM 带宽,通常不是 CPU 本身,因此让多个线程争夺相同的内存可能不是最好的设计。 通常最好重构几个通过小消息进行通信的单独进程。

All modern OSs distribute threads on all available cores; but there are several languages or libraries that prevent this from happening. the most common issues are:

  • green threads. it used to have a performance advantage when multiple CPUs were rare and OSs weren't optimised enough. there were a couple Java VMs that boasted this as a feature, later turned to M:N scheme, and i think it's now N:N everywhere.

  • GIL:Global Intepreter Lock. some scripting languages have a lot of global state deep in the interpreter loop, so there's a single big (mutex) lock to ensure consistency; but that prevents two threads of the same 'space' to run simultaneously. At least Python and Lua have this problem. in these cases it's preferred to use multiple processes instead of multiple threads.

also, it's good to remember that the biggest bottleneck in most cpu-bound applications is the RAM bandwith, usually not the CPU itself, so having several threads fighting for the same memory might not be the best design. it's usually much better to refactor in several separate processes that communicate via small messages.

夜空下最亮的亮点 2024-07-20 07:18:34

在每个操作系统上。 这几乎就是线程的定义。

如果您创建一个启动两个线程的应用程序,那么操作系统能够将它们放在两个单独的核心上。 对于 Windows、OSX、Linux 以及您能想到的任何其他操作系统都是如此。

On every operating system. That's pretty much the definition of a thread.

If you create an application which starts two threads, then the OS is able to put these on two separate cores. That's true for Windows, OSX, Linux, and any other OS you can think of.

捂风挽笑 2024-07-20 07:18:34

既然您“掌握了技能”,我假设您已经知道几乎所有现代操作系统都会在多个内核上执行您的线程(如果它们可用)并且您的线程不存在某种锁定问题,从而有效地使它们成为顺序的。

因此,我猜测您实际上是在问如何将线程绑定到内核,以便它们不会相互竞争。 这是通过设置线程的处理器亲和力来完成的。 以下是有关 Windows 和 Linux 的文章的链接。 我确信其他风格的 Unix 也存在其他的。 我还要指出,这通常是不必要的,因为除了某些特殊情况之外,操作系统更知道在哪里安排您执行的线程。 请记住,现代操作系统是多进程的,因此您的线程不仅相互竞争,而且还与机器上所有其他进程的线程竞争。 根据负载,将线程限制为单个核心实际上可能会使它们更快。

http://www.microsoft.com/ technet/prodtechnol/windows2000serv/reskit/core/fnef_mul_dnpl.mspx?mfr=true

http://www.ibm.com/developerworks/linux/library/l-affinity.html

Since you "got skills," I'm going to assume you already know that pretty much all modern OS's will execute your threads over multiple cores if they are available and your threads don't have some sort of locking issue that effectively makes them sequential.

So I'm going to guess that you're really asking how to bind your threads to cores so that they won't compete with one another. This is done by setting the processor affinity of the thread. Below are links to articles on this for Windows and Linux. I'm sure others exist for other flavors of Unix as well. I'll also note that this usually isn't necessary, as outside of some special cases the OS knows better where to schedule threads that you do. Remember, modern OSes are multiprocess, so your threads aren't just competing with each other, they are competing with the threads from all the other processes on the box. Depending on load, limiting your threads to a single core may actually make them faster.

http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/core/fnef_mul_dnpl.mspx?mfr=true

http://www.ibm.com/developerworks/linux/library/l-affinity.html

仲春光 2024-07-20 07:18:34

AFAIK,几乎每个现代操作系统都会跨多个核心调度线程。 当然,我玩过的任何 Unix 变体都没有丝毫问题,而且我相当确定所有 Windows 都能很好地处理它。 编译器不是问题,因为本机线程是操作系统级别的东西,因此编译器只是向下传递系统调用。

有几种语言(例如 Ruby)不使用本机线程,而是使用自己的“绿色”线程,这些线程在解释器中实现,因此对于操作系统来说看起来像单个线程,但它们是例外而不是规则,并且在文档中通常很明显发生了什么。

Pretty much every modern OS out there will schedule threads across multiple cores, AFAIK. Certainly no variant of Unix that I've ever played with has the slightest problem with it, and I'm fairly certain that all the Windowses handle it fine. The compiler isn't an issue, as native threads are an OS-level thing, so the compiler just passes the syscall on down.

There are a few languages (such as Ruby) that don't use native threads, and instead use their own "green" threads, which are implemented in the interpreter and hence look like a single thread to the OS, but they're the exception rather than the rule, and it's usually pretty obvious in the docs what's going on.

携君以终年 2024-07-20 07:18:34

让我们做一个小小的区别。 线程化的软件不一定会同时在两个内核上运行。

您需要编写支持同时多线程 (SMT) 的代码。 大多数操作系统都毫无问题地支持这一点 - 唯一真正的区别在于您的软件如何处理锁定和资源。 如果您的线程完全依赖于相同的内存或资源,那么就会出现争用,并且其中一个或另一个会因等待资源、内存或其他锁而停滞不前。

大多数具有线程的编程语言也能够做到这一点——确保它同时运行实际上取决于程序员。

您可以在此处找到有关如何使用 Visual Studio C++ 在 Windows 中执行此操作的信息:

http ://msdn.microsoft.com/en-us/library/172d2hhw.aspx

有很多关于这方面的教程,特别是针对 Windows(C#、C++、VB 等)的教程 - 可以通过搜索找到它们:

< a href="http://www.google.com/search?q=simultaneous+multithreading+C%2B%2B" rel="nofollow noreferrer">http://www.google.com/search?q=simultaneous +多线程+C%2B%2B

-Adam

Let's make a small distinction. Software that is threaded isn't necessarily going to run on two cores simultaneously.

You need to write code that is Simultaneous Multi Threading (SMT) capable. Most OSs support this without issue - the only real difference is in how your software deals with locking and resources. If your threads depend on the same memory or resources at all, there's going to be contention and points in time where one or the other is stalled waiting for a resource, memory, or other lock.

Most programming languages that have threading are capable of this as well - making sure it runs simultaneously is really up to the programmer.

You can find information on how to do this in Windows with Visual Studio C++ here:

http://msdn.microsoft.com/en-us/library/172d2hhw.aspx

There are many tutorials on this, especially for Windows (C#, C++, VB, etc) - they can be found by searching:

http://www.google.com/search?q=simultaneous+multithreading+C%2B%2B

-Adam

ヅ她的身影、若隐若现 2024-07-20 07:18:34

正如其他人所说,任何现代操作系统都会为您执行此操作。 然而,它的执行方式会对性能产生很大影响,因此您可能希望按照操作系统预期的方式使用线程。 这篇维基百科文章似乎对主要使用的调度技术有一个不错的概述操作系统。

As others have stated, any modern operating system will do this for you. The way in which it does it can have large impacts on performance, however, so you'll probably want to use threads in the manner your OS intended. This Wikipedia article seems to have a decent overview of the scheduling techniques used by the major operating systems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文