在vista win2003 win7(函数略有不同)中,都有专门的api返回当前线程所在的cpu,但xp下就没有,只能自己搞。一下是在国外一网站上找的自己写的函数来实现这一功能:
(注:vista win2003 的api是GetCurrentProcessorNumber() win7是GetCurrentProcessorNumberEx() )
GetCurrentProcessorNumber
The GetCurrentProcessorNumber() function is not available in XP. Here is a VC++ version of the function that works with Windows XP on Intel x86 single, hyperthreaded, multicore and multi-socket systems. It makes use of the APIC ID returned by the CPUID instruction. This is in the range 0 .. N-1, where N is the number of logical CPUs.
Source Code
//
// GetCurrentProcessorNumber.cpp
//
// an XP version of GetCurrentProcessorNumber()
//
// 14/11/07 first version
//
#include "stdafx.h"
#define NTHREADS 8
//
// GetCurrentProcessorNumberXP
//
DWORD GetCurrentProcessorNumberX