Search code examples
windowsprocessor

Determine on which physical processor my code is currently running


Is there a Windows API or any way to determine on which physical processor/core my current thread runs? I don't need that information. I'm just curious.

I'm not interested in the processors the thread is allowed to run on. I would like to know on exactly which one it currently runs. I know that the threads switch pretty fast from one to another...


Solution

  • Threads will often switch from processor to processor, so it's kind of meaningless, but you can use GetCurrentProcessorNumber.

    As others have said, you can use GetProcessAffinityMask or GetThreadIdealProcessor, but those will only work if you've already set an affinity mask or ideal processor for the thread.