Can Pthreads Guarantee Exclusive CPU Assignment for Each Thread?

  • Thread starter Thread starter noelloen
  • Start date Start date
  • Tags Tags
    cpu Multiple
Click For Summary
SUMMARY

This discussion addresses the assignment of threads to processors using Pthreads in C. It confirms that using the function pthread_processor_bind_np() allows for explicit binding of threads to specific processors, ensuring one-to-one assignment. Without this specification, the operating system's scheduling algorithm may result in multiple threads running on a single processor. Additionally, the conversation touches on the possibility of redistributing jobs among processors using inter-process communication (IPC) methods.

PREREQUISITES
  • Understanding of Pthreads in C programming
  • Familiarity with CPU scheduling algorithms
  • Knowledge of inter-process communication (IPC) techniques
  • Basic concepts of multi-threading and processor affinity
NEXT STEPS
  • Research the pthread_processor_bind_np() function for binding threads to processors
  • Explore CPU scheduling algorithms and their impact on thread performance
  • Learn about inter-process communication (IPC) methods for job redistribution
  • Investigate the use of cthreads_thread_alloc(..., node) for thread allocation in C
USEFUL FOR

This discussion is beneficial for C developers, system programmers, and anyone involved in optimizing multi-threaded applications on multi-core processors.

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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 25 ·
Replies
25
Views
3K
Replies
6
Views
5K
Replies
2
Views
2K
Replies
8
Views
6K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K