Mutli Core threading

I'm currently looking for some resource on multi-core threading. I need to get the full power of the CPU's this application will be targeting. I've tried google and it's not going well. Can anyone provide for me a link to a page that gives good information on how to thread over multiple cores in c++?

EDIT: Posix or windows, doesnt matter. I'm apt with both.
Last edited on
You need to seperate parallel work into tasks that are run in different threads.

It's the operating systems scheduler's job to decide when and where threads of execution run, you don't need to worry about that.
Actually when I first learned multi-threading it occur to me some basic question. If I test on my desktop PC that has only ONE CPU, then multi-threading won't seize all the benefits isn't it ? It is still thread by thread instructions executed by the CPU sequentially isn't it ?

Therefore I conclude, if the computer or server has > 1 CPU then multi-threading will have more impact.

Am I wrong in my assumption on multi-threading benefits ?

As i understand threading on a single CPU machine, it could be used to run different programs at the "same" time. Another benefit of threading would be for your Program to be able to compute something and give the user the feeling, that he could still make changes to the interface.

In an non threaded environment you would not be able to click a button, as long as the program is computing something else. Or you as a programmer would have to write code during long computations to check for changes of the user interface.

The solution to this problem is leaving the OS with the ability to divide the CPU time for different threads (the programmer has to write code which is threadable). If the time for a thread is up the OS will allow access to the CPU for the next thread. How the CPU time divided is managed by the OS.

With two CPUs the OS can allow two threads access to CPU time at the same time. For each CPU one thread could be run simultaneous. This means, if there is an application which is using the CPU massively but has only one thread it would be as fast on a dual core machine, as on a single core machine. If it has two threads using massive amounts of CPU time it will be about twice as fast on a dual core machine. With more cores you could run more threads at the same time.

Thus the impact of multi threading and the amount of CPUs in a machine depends on the running programs and the design of the programs.
Last edited on
I agree with Darokthar.

If your application is multithreaded, it can scale to larger hardware more easily.

A multithreaded app can still perform better than a single threaded app on a single CPU. It all depends on what you're doing. For example, if one thread is doing lots of I/O, the CPU can be utilised by another thread while that one is blocked. Again, it all depends what else happening on the box.
An advantage of multithreading on single CPU machine can be achieved in case if one thread waits I/O and another can perform computations. This technique can improve performance of some application on single CPU machine. One of the easiest way to start multi-thread programming is OpenMP technique ( http://en.wikipedia.org/wiki/OpenMP ).
Also take a look at OpenCL for data-parallel algorithms. AMD's implementation allows one to run OpenCL on the CPU. Intel's TBB is also interesting, but I have not played with it as much as I would like to. For general-purpose multi-threading, the Boost Thread library can't be beat.
Topic archived. No new replies allowed.