+#if defined _SC_NPROCESSORS_ONLN
+ { /* This works on glibc, MacOS X 10.5, FreeBSD, AIX, OSF/1, Solaris, Cygwin,
+ Haiku. */
+ long int nprocs = sysconf (_SC_NPROCESSORS_ONLN);
+ if (0 < nprocs)
+ return nprocs;
+ }
+#endif
+
+#if HAVE_SYSCTL && defined HW_NCPU
+ { /* This works on MacOS X, FreeBSD, NetBSD, OpenBSD. */
+ int nprocs;
+ size_t len = sizeof (nprocs);
+ static int mib[2] = { CTL_HW, HW_NCPU };
+
+ if (sysctl (mib, ARRAY_SIZE (mib), &nprocs, &len, NULL, 0) == 0
+ && len == sizeof (nprocs)
+ && 0 < nprocs)
+ return nprocs;
+ }