Community
cancel
Showing results for 
Search instead for 
Did you mean: 
postaquestion
Beginner
41 Views

Nuts and Bolts of Multithreaded Programming article

This is a question about Tim Mattson's article entitled Nuts and Bolts of Multithreaded Programming.

Assuming you have two threads A & B, how do you tell one core to do A's processing, and the other B's?

0 Kudos
2 Replies
41 Views

We forwarded this question to the author, who provided the following information:

If you look at the major APIs for multithreading, youll notice that they dont include a way to assign specific threads to processors. In the overwhelming majority of cases, this would be a bad thing to do. Why? Because the operating system manages all the threads running on the system and goes to great lengths to balance the load. If you start assigning threads to specific processors, you interfere with the OS scheduling, and that is usually not a good idea.

Note that in the overwhelming majority of cases, if your computer isnt busy with other CPU-intensive work, a pair of threads will tend to be assigned to each to the two cores. Hence, you are almost assured of getting the behavior you requested in your question, i.e. one thread to each core.

By the way, the technical issues behind your question are a frequent topic of conversation among designers of multi-threaded languages. The problem isnt usually with the initial distribution of threads on the system. The OS scheduler does a pretty good job of evenly spreading out the threads. The problem is with the caches. If Ive gone to great lengths to fill my caches with the data they need and then the OS migrates my threads to improve the load balance, my performance could suffer due to all the extra cache misses. This will be even more important on systems with complex cache hierarchies (such as a multiple socket system with multi-core processors in each socket). Hence, you may someday see changes in multithreading APIs to address this issue and somehow lock threads down to processors. This is a controversial topic, however, and it will take a while to work out how APIs need to change (if at all) to address this problem.

==

Lexi S.

IntelSoftware NetworkSupport

h ttp://www.intel.com/software

Contact us

smuthiya
Beginner
41 Views

If you are using the OS APIs to create a new thread, some OSes may support something called "processor affinity" for the thread. This could be used to schedule your thread on a particular core. Processor affinity is just a request to the OS scheduler and the OS scheduler may decide to run the thread on any core it deems fit.
Reply