In a multi-processor environment, the scheduler has to deal with task allocation on multiple processors or cores. From a Linux perspective, processes and threads are the same thing; both are represented by the struct task_struct kernel structure. There may be the need to force two or more tasks (that is, threads or processes) to run on the same processor to leverage, for example, the cache by avoiding the cache invalidation. This recipe will teach you how to set a hard affinity on a task.
Learning about processor affinity
How to do it...
In this recipe, we'll develop a small piece of software in which we'll force it to run on a CPU:
- On a shell, open a new source file called schedAffinity.cpp. What we want is...