The C ++ standard does not allow the establishment of thread affinity. To do this, you will need to use boost or your system API.
NOTE. Although explicit affinity management can lead to large rewards, it is also risky. This can lead to disabling some optimizations implemented by the system's own scheduler, which is especially bad when the processes that you control using this method are not the most difficult on your system. In addition, affinity management can quickly go wrong: imagine that you accidentally load 90% of your load onto one or two cores on your (todayโs usual) octo-cardiac system. Ultimately, Affinity management will need AI to work well in the increasingly complex systems that we encounter, but a simple rule-based management can work well if you can accurately predict the process load.
EDIT: so that your OS does not plan anything else in this kernel, you will need another OS function. As mentioned in the comments, isolcpus allows this to be achieved on Linux.
source share