How to get the number of cores in Win32?

I am writing a program in C on windows that should run as many threads as there are available kernels. But I do not know how to get the number of cores. Any ideas?

+3
source share
4 answers

You can call GetSystemInfothe WinAPI function; it returns a structure SYSTEM_INFOthat has the number of processors (the number of cores in a system with multiple cores).

+6
source

You can read the environment variable NUMBER_OF_PROCESSORS.

+5
source

, .NET C, :

+1

"cmd" Windows "cmd.exe". :

WMIC CPU Get /Format:List

"NumberOfCores" "NumberOfLogicalProcessors". , . , :

NumberOfLogicalProcessors = NumberOfCores * .

​​ , , .

.

0

Source: https://habr.com/ru/post/1740708/


All Articles