确定我的代码当前在哪个物理处理器上运行 [英] Determine on which physical processor my code is currently running

查看:40
本文介绍了确定我的代码当前在哪个物理处理器上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有 Windows API 或任何方法可以确定我当前的线程在哪个物理处理器/核心上运行?我不需要那个信息.我只是好奇.

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...

推荐答案

线程经常会从处理器切换到处理器,所以有点无意义,但你可以使用 GetCurrentProcessorNumber.

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

正如其他人所说,您可以使用 GetProcessAffinityMaskGetThreadIdealProcessor,但这些只有在您已经为线程设置了关联掩码或理想处理器时才有效.

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.

这篇关于确定我的代码当前在哪个物理处理器上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆