Re: Getting the number of CPUs?
Re: Getting the number of CPUs?
- Subject: Re: Getting the number of CPUs?
- From: Stéphane Sudre <email@hidden>
- Date: Tue, 7 Aug 2001 20:02:56 +0200
On mardi, ao{t 7, 2001, at 07:52 PM, Ken Tabb wrote:
Hi,
is there any Cocoa-y way of getting the number of CPUs on the host? I'm
aiming to use this as part of a thread-spawning decision process (so
that
a single processor machine doesn't get twice as many threads as it needs
to do the job).
I don't know but I'm using this:
#include <mach/mach.h>
#include <mach/bootstrap.h>
#include <mach/mach_error.h>
kern_return_t error;
mach_port_t host_control, device, wledger, pledger, security;
processor_array_t tArray;
mach_msg_type_number_t tProcNumber;
mach_msg_type_number_t i;
error = bootstrap_ports(mach_task_self(), &host_control, &device,
&wledger, &pledger, &security);
if (error != KERN_SUCCESS) {
mach_error("bootstrap_ports", error);
}
error=host_processors(host_control,&tArray,&tProcNumber);
if (error == KERN_SUCCESS)
{
CPUNumber_=tProcNumber;
}
else
{
mach_error("host_processors", error);
}
return self;