问题描述
我使用(HANDLE)_beginthreadex()创建了一个C ++ Windows控制台应用程序,其中使用x处理程序线程控制1000个工作线程。
I have created a C++ windows console application using (HANDLE)_beginthreadex() in which 1000 worker threads are controlled using x handler threads.
处理程序线程将导致最快的时间,但在测试后,我发现使用100个处理程序线程导致最快的时间。
测试是在四核intel i7处理器(支持超线程)上进行的。
Initially I thought that 1000 handler threads would result in the quickest time but after testing I have found that using 100 handler threads results in quickest time.The testing was carried out on a quad core intel i7 processor (supports hyperthreading)
我不知道为什么这个数字的线程产生最佳性能。由于我的处理器只能同时处理8个线程,我会认为8将是最好的性能。
I'm not sure what to write for my reasoning of why that number of threads results in the best performance. As my processor can only handle 8 threads simultaneously, I would have thought 8 would have been the best performance.
我在写一个关于应用程序的小报告,并且必须确定能够获得最佳性能的线程数,并解释为什么会出现这种情况。
I'm writing a small report on the application and have to identify the number of threads that results in the best performance and explain why this is the case.
推荐答案
想要一次最多有8个活动主题。有很多原因为什么8可能不是理想的数字一般,但它是一个很好的赌注在你的线程的工作不是CPU的限制。如果在这种情况下你的线程太少,你会浪费时间,而太多,当然会导致不必要的争用 - 可能导致太多的上下文切换。
You want to have 8 active threads at a time ideally. There are many reasons why 8 might not be the ideal number in general, but it's a good bet the work in your threads is not CPU limited. If you have too few threads in that case, you would be wasting time, while too many would, of course, cause undue contention -- and possibly be causing too many context switches.
这篇关于线程控制台应用程序在c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!