O'Reilly logo

Delphi Cookbook - Second Edition by Daniele Teti

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parallelize using the parallel for

One of the first loops that any programmer starts to know is the for loop. In this recipe, we'll see a particular type of for loop: the parallel one. To be clear, this parallel for loop is not a new language feature but is a sort of it implemented as a static class method.

The parallel for loop is part of the Parallel Programming Library and is implemented by the TParallel class. Here's one of its (overloaded) versions and a utilization example:

//declaration
class method TParallel.&For(ALowInclusive, AHighInclusive: 
Integer; const AIteratorEvent: TProc<Integer>): TLoopResult;

//used as follows
TParallel.&For(1,10,
  procedure(Index: Integer)
  begin 
    //executed 10 times with index 1..10
  end);

What is different about ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required