English 中文(简体)
我如何在C#中找到我的线程正在运行的处理器?
原标题:How do I find the processor on which my thread is running in C#?

在C#中,我如何找到运行我的线程的处理器?

最佳回答

这不一定是一个恒定的问题,线程可能会在其生命周期内被安排到不同的核心上。如果您想要将特定线程绑定到特定的 CPU,则可以设置亲和力掩码。有关在 .Net 中可以执行的详细信息,请参阅 Thread.BeginThreadAffinity 的 API 文档

问题回答

在我看来,.NET线程可能没有绑定到任何本地线程。.NET运行时可以随时在不同的本地线程和处理器之间移动.NET线程。

我不确定您是否能够做到。您可以获取进程关联掩码(GetProcessAffinityMask)并设置相同的掩码(SetProcessAffinityMask)。您还可以设置线程关联掩码,但我的理解是这样做将限制线程在您设置的关联掩码之一的处理器上运行。

如果你正在研究运行在特定核心上的特定线程,你可能想设置进程亲和掩码来定义你的代码可以运行的核心集,然后你的进程中的线程将在选定的核心之间浮动。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签