这个确实很有道理啊,INC指令在多核情况下不是原子操作了。这点向大牛学习了~但是,这里: 您可能把Affinity和Ideal Processor记混了吧,这是我查MSDN上的: Thread Affinity: Thread affinity forces a thread to run on a specific subset of processors. // 注意"forces" Thread Ideal Processor: Use the SetThreadIdealProcessor function to specify a preferred processor for a thread. This does not guarantee that the ideal processor will be chosen, but provides a useful hint to the scheduler.
2.试试SetProcessAffinityMask( GetCurrentProcess(), 1 );
多核下的多线程,可能涉及Cache miss增多的问题。可能是各个核使用的不是一个Cache,可能会因为Cache失效增多而造成性能下降。
2.用SetThreadAffinityMask。线程亲缘性。
当然,单核下也可能出现这个问题,但是多核下出错的可能性更大。
多核下多线程之间互相打架的几率大了,所以有些单核下没有暴露出来的bug现形了。
SetThreadAffinityMask可以让线程尽可能在某处理器上运行,但还是受系统调度的。
您可能把Affinity和Ideal Processor记混了吧,这是我查MSDN上的:
Thread Affinity:
Thread affinity forces a thread to run on a specific subset of processors. // 注意"forces"
Thread Ideal Processor:
Use the SetThreadIdealProcessor function to specify a preferred processor for a thread. This does not guarantee that the ideal processor will be chosen, but provides a useful hint to the scheduler.