Is it possible to set CPU affinity in boost threads ((i.e. setting each thread to run on a different CPU)? Is there any tutorial/documentation you can suggest on this? Googling does not return much info except the following thread where the specified example (boost-bind_processor.v1.tar.gz) is no longer present in the file server. Thanks.
Asked
Active
Viewed 3,419 times
5
2 Answers
-1
Just don't. Most of the time when you think this will help things, it just makes them worse.
Every restriction you place on the system has a cost. The scheduler is very smart and the more restrictions you force on it, the worse it will perform. The scheduler will not move a thread from one core to another unless it has a good reason.

David Schwartz
- 179,497
- 17
- 214
- 278
-
8The boost API has a method named native_handle which returns the underlting posix thread. I preformed the required setting on the underlying posix thread. – F. Aydemir Nov 16 '11 at 15:20
-
1I agree, don't do this for the normal applications. However, you might be writing a high performance service on a NUMA platform (which is basically every platform now). In which case it can be a win to set the processor affinity for some threads. You want to do network reads/writes from the node nearest the PCI bus with the NIC on it, etc. That said, yes, there is a high cost; it's in your time & labor. You have to tune for specific hardware configurations and run regressions anytime the underlying hardware changes or drivers get updated or the OS gets patched. – oz10 Apr 28 '16 at 16:21
-2
In case of .NET apps, you probably need to look into something called ProcessorAffinity
.

s_nair
- 812
- 4
- 12