В Qt нашел решение. $QTDIR/src/corelib/thread/qthread_unix.cpp
| Код | int QThread::idealThreadCount() { int cores = -1;
#if defined(Q_OS_MAC) // Mac OS X cores = MPProcessorsScheduled(); #elif defined(Q_OS_HPUX) // HP-UX struct pst_dynamic psd; if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) == -1) { perror("pstat_getdynamic"); cores = -1; } else { cores = (int)psd.psd_proc_cnt; } #elif defined(Q_OS_BSD4) // FreeBSD, OpenBSD, NetBSD, BSD/OS size_t len = sizeof(cores); int mib[2]; mib[0] = CTL_HW; mib[1] = HW_NCPU; if (sysctl(mib, 2, &cores, &len, NULL, 0) != 0) { perror("sysctl"); cores = -1; } #elif defined(Q_OS_IRIX) // IRIX cores = (int)sysconf(_SC_NPROC_ONLN); #elif defined(Q_OS_INTEGRITY) // as of aug 2008 Integrity only supports one single core CPU cores = 1; #elif defined(Q_OS_SYMBIAN) // ### TODO - Get the number of cores from HAL? when multicore architectures (SMP) are supported cores = 1; #elif defined(Q_OS_VXWORKS) // VxWorks # if defined(QT_VXWORKS_HAS_CPUSET) cpuset_t cpus = vxCpuEnabledGet(); cores = 0;
// 128 cores should be enough for everyone ;) for (int i = 0; i < 128 && !CPUSET_ISZERO(cpus); ++i) { if (CPUSET_ISSET(cpus, i)) { CPUSET_CLR(cpus, i); cores++; } } # else // as of aug 2008 VxWorks < 6.6 only supports one single core CPU cores = 1; # endif #else // the rest: Linux, Solaris, AIX, Tru64 cores = (int)sysconf(_SC_NPROCESSORS_ONLN); #endif
return cores; }
|
|