The Task Parallel Library (TPL) is the task parallelism component of the Parallel Extensions to .NET. It exposes parallel constructs like parallel For and ForEach loops, using regular method calls and delegates, thus the constructs can be used from any CLI languages. The job of spawning and terminating threads, as well as scaling the number of threads according to the number of available processors, is done by the library itself.
TPL also includes other constructs like Task and Future. A Task is an action that can be executed independent of the rest of the program. In that sense, it is semantically equivalent to a thread, except that it is a more light-weight object and comes without the overhead of creating an OS thread. Tasks are queued by a Task Manager object and are scheduled to run on multiple OS threads in a thread pool when their turn comes.
Future is a task that returns a result. The result is computed in a background thread encapsulated by the Future object, and the result is buffered until it is retrieved. If an attempt is made to retrieve the result before it has been computed then the requesting thread will block until the result is available.
The other construct of TPL is Parallel class. TPL provides a basic form of structured parallelism via three static methods in the Parallel class:
- Parallel.Invoke
- Executes an array of Action delegates in parallel, and then waits for them to complete
- Parallel.For
- Parallel equivalent of a C# for loop
- Parallel.ForEach
- Parallel equivalent of a C# foreach loop
Read more about this topic: Parallel Extensions
Famous quotes containing the words task, parallel and/or library:
“Method goes far to prevent trouble in business: for it makes the task easy, hinders confusion, saves abundance of time, and instructs those that have business depending, both what to do and what to hope.”
—William Penn (16441718)
“The universe expects every man to do his duty in his parallel of latitude.”
—Henry David Thoreau (18171862)
“That a famous library has been cursed by a woman is a matter of complete indifference to a famous library. Venerable and calm, with all its treasures safe locked within its breast, it sleeps complacently and will, so far as I am concerned, so sleep forever. Never will I wake these echoes, never will I ask for that hospitality again ...”
—Virginia Woolf (18821941)