Parallel Extensions - Task Parallel Library

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:

    Your children are not here to fill the void left by marital dissatisfaction and disengagement. They are not to be utilized as a substitute for adult-adult intimacy. They are not in this world in order to satisfy a wife’s or a husband’s need for love, closeness or a sense of worth. A child’s task is to fully develop his/her emerging self. When we place our children in the position of satisfying our needs, we rob them of their childhood.
    Aaron Hess (20th century)

    The universe expects every man to do his duty in his parallel of latitude.
    Henry David Thoreau (1817–1862)

    Readers transform a library from a mausoleum into many theaters.
    Mason Cooley (b. 1927)