...

/

taskPool.parallel()

taskPool.parallel()

You will learn about the working of the parallel() function in this lesson.

Working of taskPool.parallel() function

This function can also be called simply as parallel().

parallel() accesses the elements of a range in parallel. An effective usage is with foreach loops. Merely importing the std.parallelism module and replacing students with parallel(students) as done previously, is sufficient to take advantage of all of the cores of the system:

import std.parallelism; 
// ...
    foreach (student; parallel(students)) {

We have seen earlier in the foreach for structs and classes chapter that the expressions that are in foreach blocks are passed to opApply() ...