Index: /trunk/src/kmk/main.c
===================================================================
--- /trunk/src/kmk/main.c	(revision 2980)
+++ /trunk/src/kmk/main.c	(revision 2981)
@@ -1239,14 +1239,31 @@
 # ifdef WINDOWS32
     /* Windows: Count the active CPUs. */
-    int cpus, i;
-    SYSTEM_INFO si;
-    GetSystemInfo(&si);
-    for (i = cpus = 0; i < sizeof(si.dwActiveProcessorMask) * 8; i++)
+    int cpus;
+
+    /* Process groups (W7+). */
+    typedef DWORD (WINAPI *PFNGETACTIVEPROCESSORCOUNT)(DWORD);
+    PFNGETACTIVEPROCESSORCOUNT pfnGetActiveProcessorCount;
+    pfnGetActiveProcessorCount = (PFNGETACTIVEPROCESSORCOUNT)GetProcAddress(GetModuleHandleW(L"kernel32.dll"),
+                                                                            "GetActiveProcessorCount");
+    if (pfnGetActiveProcessorCount)
+      cpus = pfnGetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
+    /* Legacy (<= Vista). */
+    else
       {
-        if (si.dwActiveProcessorMask & 1)
-          cpus++;
-        si.dwActiveProcessorMask >>= 1;
+        int i;
+        SYSTEM_INFO si;
+        GetSystemInfo(&si);
+        for (i = cpus = 0; i < sizeof(si.dwActiveProcessorMask) * 8; i++)
+          {
+            if (si.dwActiveProcessorMask & 1)
+              cpus++;
+            si.dwActiveProcessorMask >>= 1;
+          }
       }
-    return cpus ? cpus : 1;
+    if (!cpus)
+      cpus = 1;
+    if (cpus > 64)
+      cpus = 64; /* (wait for multiple objects limit) */
+    return cpus;
 
 # elif defined(__OS2__)
