Threads http://www.albahari.com/threading/ Wouldn't running my program on a multi-core machine automatically improve performance; after all aren't there more threads? The answer is no!
Parallel vs. Concurrent:
Concurrency is about executing multiple un-related tasks in a concurrent mode. Parallel. Parallelism is taking a certain task and dividing it into a set of related tasks to be executed concurrently. Parallel Programming still has the same problems of concurrent programming (deadlocks, data races, etc...), and introduces new challenges, most notably, sharing and partitioning data across these related threads.
dynamic partitioning work into the smallest feasible units which will make use of the most feasible number of available threads. This will solve the load-imbalance issue.
Creating and killing threads is an expensive procedure. This brings us to the final partitioning option: the .NET Thread Pool to solve thread overhead.
The thread pool is a fire-and-forget programming model. Once you create a thread by code, you basically have no way to perform any operations on it. There is no support for continuing, composing, monitoring data flow, performing work cancellation, and work waiting. The solution is .NET 4.0 Task-based Programming
The Parallel Programming model of .NET 4.0 is composed of the following:
- The Task Parallel Library (TPL): this is the base of the Task-based programming discussed in the previous section. It consists of:
Taskclass: the unit of work you will code against instead of the previous thread model.Parallelclass: a static class that exposes a task-based version of some parallel-nature problems. More specifically, it contains the following methods:ForForeachInvoke- Parallel LINQ (PLINQ): built on top of the TPL and exposes the familiar LINQ as Parallel extensions.
Introducing .NET 4.0 Parallel Programming
No comments:
Post a Comment