Determine which physical processor my code runs on

Is there a Windows API or some way to determine which physical processor / kernel the current thread is running on? I do not need this information. I'm just curious.

I'm not interested in processors that allow threading. I would like to know at what exact moment it works. I know that threads switch quite quickly from one to another ...

+3
source share
3 answers

Threads often switch from processor to processor, so this is pointless, but you can use it GetCurrentProcessorNumber.

, GetProcessAffinityMask GetThreadIdealProcessor, , .

+4
+3

Windows API, SetThreadAffinityMask SetProcessAffinityMask.

They work by setting bits in a bitmask, where each bit represents a processor that can be scheduled for your thread or process:

BOOL WINAPI SetProcessAffinityMask(
  __in  HANDLE hProcess,
  __in  DWORD_PTR dwProcessAffinityMask
);

Call GetProcessAffinityMask to find out which processors are available for use in these calls.

+2
source

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


All Articles