C# – the difference in .NET between developing a multithreaded application and parallel programming

cconcurrencymultithreadingparallel-processingtask-parallel-library

Recently I've read a lot about parallel programming in .NET but I am still confused by contradicting statements over the texts on this subject.

For example, tThe popup (upon pointing a mouse on tag's icon) description of the stackoverflow.com task-parallel-library tag:

"The Task Parallel Library is part of .NET 4. It is a set of APIs tpo
enable developers to program multi-core shared memory processors"

Does this mean that multi-core-d and parallel programming applications impossible using prior versions of .NET?

Do I control a multicore/parallel usage/ditribution between cores in .NET multithreaded application?

How can I identify a core on which a thread to be run and attribute a thread to a specific core?

What has the .NET 4.0+ Task Parallel Library enabled that was impossible to do in previous versions of .NET?

Update:
Well, it was difficult to formulate specific questions but I'd like to better understand:

What is the difference in .NET between developing a multi-threaded application and parallel programming?

So far, I could not grasp the difference between them

Update2:
MSDN "Parallel Programming in the .NET Framework" starts from version .NET 4.0 and its article Task Parallel Library tells:

"Starting with the .NET Framework 4, the TPL is the preferred way to
write multithreaded and parallel code"

Can you give me hints how to specifically create parallel code in pre-.NET4 (in .NET3.5), taking into account that I am familiar with multi-threading development?

Best Answer

I see "multithreading" as just what the term says: using multiple threads.

"Parallel processing" would be: splitting up a group of work among multiple threads so the work can be processed in parallel.

Thus, parallel processing is a special case of multithreading.


Does this mean that multi-core-d and parallel programming applications impossible using prior versions of .NET?

Not at all. You could do it using the Thread class. It was just much harder to write, and much much harder to get it right.

Do I control a multicore/parallel usage/ditribution between cores in .NET multithreaded application?

Not really, but you don't need to. You can mess around with processor affinity for your application, but at the .NET level that's hardly ever a winning strategy.

The Task Parallel Library includes a "partitioner" concept that can be used to control the distribution of work, which is a better solution that controlling the distribution of threads over cores.

How can I identify a core on which a thread to be run and attribute a thread to a specific core?

You're not supposed to do this. A .NET thread doesn't necessarily correspond with an OS thread; you're at a higher level of abstraction than that. Now, the default .NET host does map threads 1-to-1, so if you want to depend on an undocumented implementation detail, then you can poke through the abstraction and use P/invoke to determine/drive your processor affinity. But as noted above, it's not useful.

What has the .NET 4.0+ Task Parallel Library enabled that was impossible to do in previous versions of .NET?

Nothing. But it sure has made parallel processing (and multithreading) much easier!

Can you give me hints how to specifically create parallel code in pre-.NET4 (in .NET3.5), taking into account that I am familiar with multi-threading development?

First off, there's no reason to develop for that platform. None. .NET 4.5 is already out, and the last version (.NET 4.0) supports all OSes that the next older version (.NET 3.5) did.

But if you really want to, you can do simple parallel processing by spinning up Thread objects or BackgroundWorkers, or by queueing work directly to the thread pool. All of these approaches require more code (particularly around error handling) than the Task type in the TPL.