How to get number of cores in Win32?

Alan picture Alan · Apr 12, 2010 · Viewed 15.9k times · Source

I'm writing a program in C on windows that needs to run as many threads as available cores. But I dont know how to get the number of cores. Any ideas?

Answer

James McNellis picture James McNellis · Apr 12, 2010

You can call the GetSystemInfo WinAPI function; it returns a SYSTEM_INFO struct, which has the number of processors (which is the number of cores on a system with multiple core CPUs).