//1. get core id
unsigned char get_real_core_id()
{
#ifdef _WIN64
int temp[4] = {0x0};
__cpuid(temp, 1);
return (unsigned char)((temp[1]>>24)&0xff);
#else
unsigned int ebx_value = 0;
__asm
{
mov eax, 1
cpuid
mov ebx_value, ebx
}
return (unsigned char)((ebx_value >> 24)&0xff);
#endif
}
//2. get cpu core number
SYSTEM_INFO si;
GetSystemInfo(&si);
int core_num = si.dwNumberOfProcessors;
//3. thread affinity mask
for(int i = 0; i < core_num; ++i)
{
// HANDLE * _handle = new HANDLE[core_num];
_handle[i] = _beginthreadex(...);
SetThreadAffinityMask(_handle[i],0x0001 << i); // set thread run on the special core id
}
//4. the program is on the bitbucket(Harvey123)
system info & cpu core id & thread active
最新推荐文章于 2022-12-17 20:22:46 发布
571

被折叠的 条评论
为什么被折叠?



