确定我的代码当前在哪个物理处理器上运行

编程入门 行业动态 更新时间:2024-10-26 14:33:43
本文介绍了确定我的代码当前在哪个物理处理器上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

是否有 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 20:56:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1123427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器上   物理   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!