Reputation: 6008
I want my software to create one thread per core, obviously different Macs have a different number of cores.
Does anyone know how to (programmatically, via Cocoa) determine the number of cores?
Upvotes: 4
Views: 2138
Reputation: 63667
See How do I detect a dual core CPU on iOS? It works in OS X too.
unsigned int countCores()
{
size_t len;
unsigned int ncpu;
len = sizeof(ncpu);
sysctlbyname ("hw.ncpu",&ncpu,&len,NULL,0);
return ncpu;
}
Upvotes: 2