using all 4 CPU cores....
Moderator:Moderators
let's say that we have Core 2 Quad processor and we want applications to use all 4 cores. Which job is this? operating system or the application? Do we need to code the application in a way that we will tell to use all 4 cores or this is job for the OS?
The operating system needs to support multi-threading and it needs to know how to schedule threads to run on different cores.
Then the application needs to be running multiple threads. If the application uses 4 threads then in theory it could run on all 4 cores at once, but in reality a multi-threaded application would have to be specifically written to work efficiently on more than one core at once (e.g. balancing the workload between the threads equally). A lot of applications are multi-threaded these days, but I think most of them aren't really written to take advantage of more than one core, because it can make the coding quite a bit more complicated.
Then the application needs to be running multiple threads. If the application uses 4 threads then in theory it could run on all 4 cores at once, but in reality a multi-threaded application would have to be specifically written to work efficiently on more than one core at once (e.g. balancing the workload between the threads equally). A lot of applications are multi-threaded these days, but I think most of them aren't really written to take advantage of more than one core, because it can make the coding quite a bit more complicated.
Yeah - you need a working thread scheduler to run on multiple cores at once. You also need to do some APIC magic to start the other cores. By default, a multi core computer starts up with the first core running and all others in standby, but with interrupts enabled so they can be started.
On the other hand, writing multi threaded programs is a black art in itself which a large number of such programs fail at.
The best way to write multi threaded programs is to split your program into discrete units that require the bare minimum of communication between each other, and if possible, no data sharing between each other.
When you get into situations like this, 2 or more threads can spend most of their time trying to access each others data which just results in a huge waste of time. In fact, even moderate examples of this can result in 2 threads ultimately being slower than a single thread (possibly with cooperative multitasking as a substitute for real multi threading).
Hope this makes sense
~Andrew
On the other hand, writing multi threaded programs is a black art in itself which a large number of such programs fail at.
The best way to write multi threaded programs is to split your program into discrete units that require the bare minimum of communication between each other, and if possible, no data sharing between each other.
When you get into situations like this, 2 or more threads can spend most of their time trying to access each others data which just results in a huge waste of time. In fact, even moderate examples of this can result in 2 threads ultimately being slower than a single thread (possibly with cooperative multitasking as a substitute for real multi threading).
Hope this makes sense
~Andrew

What you are slightly confused about is the difference between thread multitasking and process multitasking.so if i write huge program for banking it will not use all cores...
why then we are buying this kind of CPU's if they don't use all the power?
To start with, I shall clarify what I mean (because some people use different definitions). A process nominally has a 4GB virtual address space and 1 or more threads. A thread, on the other hand, is what your thread scheduler uses to get the program to run.
If a process has a single thread, its a single threaded process (i hope that's clear

Now, because you have 4 cores (for sake of argument), there is nothing to stop you running 4 processes at once. Each process nominally has a different 4GB virtual address space so they don't interfere with each other. If they need to communicate, they have to use the kernel.
Because of that, it is perfectly possible for you to have your kernel running on the first core, your <insert> playing music on the second core while you sit and play your <insert> on the third core, all topped off with your fourth core sitting and compiling the latest version of your kernel (why else are you on these forums

I hope this clarifys the use of use of many cores with many single threaded processes.
~Andrew
