thread affinity
unknown
c_cpp
a year ago
346 B
12
Indexable
void set_thread_affinity(int core_id) {
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(core_id, &cpuset);
pthread_t current_thread = pthread_self();
int rc = pthread_setaffinity_np(current_thread, sizeof(cpu_set_t), &cpuset);
if (rc != 0) {
std::cerr << "Error setting thread affinity: " << rc << std::endl;
}
}Editor is loading...
Leave a Comment