On which operationg system is threaded programming sufficient to utilize multiple cores?
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?
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.
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.
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
链接地址: http://www.djcxy.com/p/36864.html上一篇: SMP核心,进程和线程如何一起工作?
下一篇: 哪个操作系统的线程编程足以利用多个内核?