[erlang-questions] logical_processors_available unknown on mac
Richard A. O'Keefe
Thu Feb 18 23:54:42 CET 2016
On 19/02/16 12:46 am, Alin Popa wrote:
> On Wed, Feb 17, 2016 at 1:25 PM, Alin Popa <
> <mailto:>> wrote:
> I was recently trying to use
> `erlang:system_info(logical_processors_available).` on my mac,
> and getting `unknown` atom back; anyone has any idea if this
> is really by design?
% sysctl -a | grep cpu | head
hw.ncpu = 4
hw.cpufrequency = 3200000000
You can get at this with, e.g.,
int ans; size_t anslen = sizeof ans;
sysctlbyname("hw.activecpu", &ans, &anslen, 0, 0)
For that matter,
* hw.activecpu - The number of processors currently
available for executing threads.
* Use this number to determine the
number threads to create in SMP aware applications.
* This number can change when power
management modes are changed.
There are so many ways to count the number of CPUs on a Mac.
I suspect that hw.activecpu is the one to use; if it isn't, then
hw.logicalcpu may be the one.
More information about the erlang-questions