Skip to content

Instantly share code, notes, and snippets.

@shuffle2
Created October 28, 2019 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuffle2/2e3f2626edeefc82deadcf9673f10f8e to your computer and use it in GitHub Desktop.
Save shuffle2/2e3f2626edeefc82deadcf9673f10f8e to your computer and use it in GitHub Desktop.
int set_affinity(int cpu) {
int policy = SCHED_FIFO;
struct sched_param param = {
.sched_priority = sched_get_priority_max(policy)
};
pthread_setschedparam(pthread_self(), policy, &param);
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(cpu, &cpuset);
return pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment