识别特定线程使用的处理器(核心) [英] Identify processor (core) is used by specific thread

查看:75
本文介绍了识别特定线程使用的处理器(核心)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以识别具有特定thread-id的线程使用的物理处理器(核心)吗?

I would like to know if it is possible to identify physical processor (core) used by thread with specific thread-id?

例如,我有一个多线程应用程序,该应用程序具有两(2)个线程(例如,thread-id = 10thread-id = 20).我在具有双核处理器(核心1和核心2)的系统上运行该应用程序.那么,如何获取thread-id = 20线程使用的核心编号?

For example, I have a multithreaded application that has two (2) threads (thread-id = 10 and thread-id = 20, for instance). I run the application on a system that has a dual core processor (core 1 and core 2). So, how do I to get core number used by thread with thread-id = 20?

P.S. Windows平台.

P.S. Windows platforms.

谢谢

丹尼斯.

推荐答案

除非您使用线程亲和性,否则不会将线程分配给特定的内核.对于每个时间片,线程都可以在不同的内核上执行.这意味着,如果有一个函数可以获取线程的核心,那么当您获得返回值时,很有可能该线程已经在另一个核心上执行了.

Unless you use thread-affinity, threads are not assigned to specific cores. With every time slice, the thread can be executed on different cores. This means that if there would be a function to get the core of a thread, by the time you get the return value, there's a big chance that the thread is already executing on another core.

如果您使用的是线程亲和性,则可以看一下Windows线程亲和性函数(

If you are using thread-affinity, you could take a look at the Windows thread-affinity functions (http://msdn.microsoft.com/en-us/library/ms684847%28v=VS.85%29.aspx).

这篇关于识别特定线程使用的处理器(核心)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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