C#怎样让不同的线程运行在不同的CPU上来提高运行效率?
1:假如单独调用FindShapeModel()方法执行所需要时间为100mms ;那我用多线程调用FindShapeModel()\FindShapeModel1()所用的时间应该也是100ms 左右,但实际测试发现会大于100*2ms ,偶尔有100ms左右的情况出现。
2:求解原因,代码中有设置让线程运行在不同的CPU上,但根据实没时间,好像还是运行在同一个CPU上。
3:FindShapeModel()\FindShapeModel1()方法内容一样的,只是名称不一样。
4:硬件配置 intel core(TM)-i7-7700 CPU
private void FindShapeModel()
{
Thread.BeginThreadAffinity();
IntPtr handle = GetCurrentThread();
int id = Thread.CurrentThread.ManagedThreadId;
uint id1 = GetCurrentThreadId();
UIntPtr rtn = SetThreadAffinityMask(handle, new UIntPtr(0x000F));
uint rtn1 = GetLastError();
QueryPerformanceCounter(ref time[15]);
isFinish[0]= FindShapeModel(hv_ModelID,ho_Image);
Thread.EndThreadAffinity();
}
private void FindShapeModel1()
{
Thread.BeginThreadAffinity();
IntPtr handle = GetCurrentThread();
int id = Thread.CurrentThread.ManagedThreadId;
uint id1 = GetCurrentThreadId();
UIntPtr rtn = SetThreadAffinityMask(handle, new UIntPtr(0x0001));
uint rtn1 = GetLastError();
FindShapeModel1(hv_ModelID, ho_Image1);
Thread.EndThreadAffinity();
}
MyThread[0] = new Thread(new ThreadStart(FindShapeModel));
MyThread[0].Start();
MyThread[1] = new Thread(new ThreadStart(FindShapeModel1));
MyThread[1].Start();
相关推荐
C#多线程学习(一)
C#高级编程,多线程的相关概念,什么是进程,线程,多线程的好处等
C# 多线程编程 详解
This book provides an introduction to writing concurrent programs with “threads”. A threads facility allows you to write programs with multiple simultaneous points of execution, synchronizing through shared memory. The paper describes the basic thread and synchronization primitives, then for each primitive provides a tutorial on how to use it. The tutorial sections provide advice on the best ways to use the primitives, give warnings about what can go wrong and offer hints about how to avoid these pitfalls. The paper is aimed at experienced programmers who want to acquire practical expertise in writing concurrent programs. The programming language used is C#, but most of the tutorial applies equally well to other languages with thread support, such as Java.
unity3d逻辑程序员开发面试题.doc
unity开发面试题目 Unity3d逻辑程序员面试题 姓名: 时间(30分钟)请认真作答,字迹不要潦草 基础题: 1.C# 值类型和引用类型的区别?什么是拆装箱,如何避免 现有一Dictionary testMap ,如何删除key 小于1的元素?
c#基础知识PPT一
C#的初级用户使用说明资料,入门级好帮手,共有十几个PPT,都上传了。
ASP.NET多线程编程(一)
微软讲师ASP.NET多线程编程(一)



