开发者

What is the difference between thread affinity and process affinity?

What开发者_如何学运维 is the difference between thread affinity and process affinity?

If I have two threads and I have a dual core machine then is it possible to run these two threads in parallel on the two cores?

If I use processor affinity mask then I can control execution of a process on the cores but when I have to run threads on a particular core how can I make these threads core specific?

A very simple example will be appreciated.


What is difference between Thread Affinity and Process affinity ?

The process affinity is the default affinity mask for all threads belonging to that process. New threads will start with the process affinity mask if not specified otherwise. However, the affinity of a single thread can be changed without changing the process affinity (and the affinity masks of the other threads), and that's when there is a difference between process and thread affinties.

If I have two Threads and I have duel core machine then is it possible to run these two threads parallely on the two cores ?

Yes it is possible, but in most cases, you really should let the operating system decide... most likely it is smarter than you.

If I use processor affinity Mask then I can control execution of a process on the cores but when I have to run threads on a particular core how can I make these threads core specific ?

You would have to use p/invoke to call the unmanaged function SetThreadAffinityMask() and then use Thread.BeginThreadAffinity() to ensure that the managed thread stays with a specific OS thread. But you really don't want to do that!


I am not aware that you can set thread affinity in .net, so environment decides which threads to run on which core.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜