Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write .NET applications that utilize multi-core processors

Tags:

.net

multicore

As multi-core processors become more and more popular, I think it would be wise for me to become familiar with how to write code to take advantage of them. I am a .NET developer, and am not sure where to begin (seriously, I have no clue where to start). Any suggestions?

like image 989
Josh Stodola Avatar asked Mar 03 '09 19:03

Josh Stodola


3 Answers

Multi-core programming is essentially multi-threaded programming. As long as your application is multi-threaded, the operating system will determine which core to run which thread on.

So then, your real question should be, what kind of applications would benefit from being multi-threaded? Think of such an application, then instantiate multiple threads to solve equal portions of the problem.

like image 94
Dmitry Brant Avatar answered Nov 07 '22 22:11

Dmitry Brant


The best way to start is to grab the latest CTP of the parrallel extensions framework and start plowing through their sample code.

  • Parallel Team Page: http://msdn.microsoft.com/en-us/concurrency/default.aspx
  • Latest CTP announcement: http://blogs.msdn.com/somasegar/archive/2008/06/02/june-2008-ctp-parallel-extensions-to-the-net-fx.aspx
like image 45
JaredPar Avatar answered Nov 07 '22 23:11

JaredPar


Read up on the asynchronous programming model that .NET uses. Study the BeginXXX and EnxXXX paradigm that allows delegates to execute in the threadpool.

The Stream classes all have BeingXXX, EndXXX methods (eg BeginRead, EndRead) that allow you to do asynchronous IO. If you're working on something that heavily IO based you'll want to use these methods to increase parallelism.

like image 2
Sean Avatar answered Nov 07 '22 22:11

Sean