Explore the Task Parallel Library (TPL), which is based on the concept of a task that represents an asynchronous operation. Learn how, in some ways, a task resembles a thread or ThreadPool work item, but at a higher level of abstraction.
- [Instructor] The task parallel library is a set of public types and APIs that could be found in two different namespaces System.Threading and System.Threading.Tasks. Task parallel library is also known as TPL. TPL makes us productive by simplifying the process of adding parallelism and concurrency to applications. The vision behind TPL is for the developers to be able to maximize the performance of code while not having to worry about the nitty gritties of threading.
The real value of TPL is in scaling the degree of concurrency dynamically so as to use all the available processors in a very efficient manner. TPL is also responsible in handling partitioning of the work, scheduling threads on the ThreadPool, and allowing for cancellation of the task. In addition to that it also takes care of state management. One thing to keep in mind, though, is that even though the TPL is the preferred way to write multithreaded and parallel code not all code is suitable for parallelization and one more thing to remember is that threading of any kind has a small overhead.
If you have a function that runs in just a few milliseconds using multiple threads might not help the overall performance. In fact it could actually add some overhead. In certain cases it could even end up being slower than sequential code. For example a function having a for loop with very few iterations might not be a good candidate for using multithreading or TPL for that matter.
Released
4/2/2018- Thread safety and affinity
- Signaling
- Task Parallel Library (TPL) basics
- PLINQ introduction
- Task-based Asynchronous Pattern (TAP)
Share this video
Embed this video
Video: TPL introduction