Athlon64 X2

John Haxby jch at scalix.com
Wed Jul 6 07:45:06 UTC 2005


Robert L Cochran wrote:

> Speaking as a beginner in C where can I find good sample code that 
> does this? How can I programmatically check for multiple CPUs or a 
> multicore CPU? How can I programmatically send one thread to a 
> specific CPU or CPU core? Or do I just create multiple threads and let 
> the OS decide where to send them?

The very nature of Linux means that the vast majority of programs don't 
need to know or care about the number of CPUs in a system, whether 
physically separate, dual core or hyperthreaded.  My relatively idle 
machine has, at the moment, 127 processors and if it had more than one 
processor the kernel would be cheerfully scheduling processes to all the 
processors.   In many cases the only multi-threaded programming you need 
is a collection of cooperating processes and all multiple CPUs give you 
is a greater likelihood of race conditions.

If the programs you're writing would benefit from concurrency or 
parallelism then you need to be concerned about multiple threads.  If 
you're wondering what those terms mean then you need a beginning book on 
threads (there are quite a lot out there for a variety of programming 
languages, pick one you like the look of).   Once you're over the 
beginning then you need to be concerned more with the pattens used for 
multi-threaded programs: my personal recommendation would be for Doug 
Lea's Java threads book -- I wish I could remember the title, but I 
don't think he's written many books about thread patterns.   Yes, it's 
Java, but the concepts are generic.

The last thing you were asking about is processor affinity.   If you're 
hacking the kernel, you'll know about this.   Chances are you'll never 
need it at a user level; although the pthreads interface does allow 
setting CPU affinity for an individual thread.   There are supposed to 
be a few pathological cases where assigning a thread to a specific 
processor (or pool of processors) is the right thing to do.

jch




More information about the amd64-list mailing list