Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How we Write an example of multithreaded C# code to fill int[10000] array with random numbers. Use the optimal number of threads for the current hardware configuration.
Please Give Me soluation
Thanks & Regards

Arvind Kumar Singh
Posted
Updated 16-Aug-11 12:24pm
v2

Bear in mind that if you pass the same array around to different threads, you are likely to have issues with the core cache and data copying, and that will probably make the optimal number of threads 1 for such a trivial operation.

You should look at the Task Parallel Library as Simon mentioned if you are using .Net 4; if not, you should look at the ThreadPool. As this is presumably a homework exercise (it is a ridiculous requirement for any sort of business scenario) telling you where to start looking is as explicit as I will be.
 
Share this answer
 
 
Share this answer
 
Comments
Simon Bang Terkildsen 17-Aug-11 7:26am    
While I agree we're not to do other poeple homework or work for that matter for them, pointing them to resources they might be able to use doesn't hurt anyone and might actually teach them something.
If the OP had left out the "Please give me solution" part then I don't see anything wrong with the question whether it's homework or not.
#realJSOP 17-Aug-11 8:17am    
He's asking for a solution, not help. I wrote a highly voted article here, but he couldn't take the time to actually do research before asking for code, so screw 'em.
Simon Bang Terkildsen 17-Aug-11 8:20am    
Yeah I get what you're saying. I guess my patience has not been tried as much as yours. As I've only been an active participater here for a little over week now.
If you can use .NET 4.0 then Sacha Barber has written a series of articles about the Task Parallel Library. Here is the first one:
Task Parallel Library: 1 of n[^]

As for the optimal number of threads, I don't remember if mr. Barber convers that, but in most cases it would be best to let the ThreadPool handle that. ThreadPool is covered in mr. Barber's articles.
 
Share this answer
 
v2
Comments
BobJanova 17-Aug-11 7:11am    
You actually linked to the last article. The first one is here: http://www.codeproject.com/KB/cs/TPL1.aspx
Simon Bang Terkildsen 17-Aug-11 7:20am    
Hehe, thank you for pointing that out. I've updated the answer to link to the first article in the series.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900