Split
Split

Reputation: 299

Threading console application in c++

I have created a C++ windows console application using (HANDLE)_beginthreadex() in which 1000 worker threads are controlled using x handler threads.

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)

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.

Upvotes: 0

Views: 918

Answers (1)

Joel
Joel

Reputation: 5674

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.

Upvotes: 3

Related Questions