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:
“We Russians have assigned ourselves no other task in life but the cultivation of our own personalities, and when were barely past childhood, we set to work to cultivate them, those unfortunate personalities.”
—Ivan Sergeevich Turgenev (18181883)
“If from the earth we came, it was an earth
That bore us as a part of all the things
It breeds and that was lewder than it is.
Our nature is her nature. Hence it comes,
Since by our nature we grow old, earth grows
The same. We parallel the mothers death.”
—Wallace Stevens (18791955)
“To a historian libraries are food, shelter, and even muse. They are of two kinds: the library of published material, books, pamphlets, periodicals, and the archive of unpublished papers and documents.”
—Barbara Tuchman (19121989)