Is it still possible to set thread affinity in macOS?

104 Views Asked by At
mach_port_t thread_port = pthread_mach_thread_np(pthread_self());
thread_affinity_policy_data_t policyData1;
policyData1.affinity_tag = 1;
int b = 0;
kern_return_t t1 = thread_policy_set(thread_port, THREAD_AFFINITY_POLICY, (thread_policy_t)&policyData1, THREAD_AFFINITY_POLICY_COUNT);
if (t1 == KERN_SUCCESS)
{
    printf("set cores success");
}
else
{
    printf("fail set : %d\n", t1);
}

I think this piece of code should work in the older version of macOS to set the thread affinity, but I end up getting error code 46 in my M1 MacBook, and I noticed that there is few documentation left about using this function to change the thread affinity, so is this feature deprecated in current macOS version?

0

There are 0 best solutions below