views:

102

answers:

2

I have programm writting with C, and I want just only function in oher processor.

Does anyone know how to be thread-distribution for multi-core processors work? Can a current thread running on the times one, sometimes on the other core, depending on how busy the nuclei are straight?

Add Reply

+3  A: 

I believe you are looking for set affinity functionality.

Processor affinity is a modification of the native central queue scheduling 
algorithm in a symmetric multiprocessing operating system. Each task 
(be it process or thread) in the queue has a tag indicating its 
preferred / kin processor. At allocation time, each task is allocated to
its kin processor in preference to others.

Check out this thread which discusses the usage of setting affinity to particular thread. Excerpts from this thread:

int sched_setaffinity(pid_t pid,size_t cpusetsize,cpu_set_t *mask);

Passing 0 as the pid, and it'll apply to the current thread only, or have other
thread report their kernel pid with the linux specific call pid_t gettid(void);
and pass that in as the pid.
Praveen S
+1  A: 

I think you are asking how do threads get distributed to run on different processors in a multi-processor CPU? If so, my understanding is that this is something that is controlled by the operating system. Take a look at this SO question.

zooropa
First think you.but, i don't want parallet with .NET, but with C unter Linux, ther es no api or c Libary!!!
farka