Can Pthreads Guarantee Exclusive CPU Assignment for Each Thread?

  • Thread starter Thread starter noelloen
  • Start date Start date
  • Tags Tags
    cpu Multiple
AI Thread Summary
When initializing threads in a multi-processor environment, there is no guarantee that each CPU will have one dedicated thread. The operating system's scheduling algorithm typically determines thread distribution, which can result in uneven allocation, such as multiple threads running on one processor while others remain idle. To achieve a one-to-one assignment of threads to processors, specific functions like pthread_processor_bind_np() for POSIX threads or cthreads_thread_alloc() for cthreads can be used to bind threads to specific processors.Regarding the ability to shift jobs between processors, it is possible to move threads from one processor to another using inter-process communication (IPC) or other methods, although the specifics depend on the implementation and the threading library in use. For further reading and detailed guidance, consulting documentation on threading and processor binding in C, particularly for POSIX threads, is recommended.
noelloen
Messages
1
Reaction score
0
Hi,

First question is:
I want to assign 8 threads to 8 processors (must one to one), when I initialize the thread, does it guarantee that each CPU has one thread?
or there can be some case such that 4 threads on one process and other 4 thread on 4 processors and 3 processors have no threads at all?

Second question is:
For instance, one processor has 4 jobs running, is it possible to shift 2 of them to other processors? using IPC stuffs? or other methods?


For the above questions, is there any reference links that I can visit?
I am new to threading. Thanks ahead to anyone answer my questions.
 
Technology news on Phys.org
In C, using Posix threads, you can use pthread_processor_bind_np() to associate a thread to a specific processor. Using cthreads it's something like cthreads_thread_alloc(..., node) where node is the processor to run on.
If you don't specify, then the thread will probably run on a processor chosen depending on the OS scheduling algorithm i would imagine.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top