Skip to Main Content
Mastering Delphi Programming: A Complete Reference Guide
book

Mastering Delphi Programming: A Complete Reference Guide

by Primož Gabrijelčič
November 2019
Beginner to intermediate content levelBeginner to intermediate
674 pages
15h
English
Packt Publishing
Content preview from Mastering Delphi Programming: A Complete Reference Guide

Parallelizing a loop

Let us now return to Mr. Smith's problem. He is calling the FindPrimes method, which checks the primality of natural numbers in a for loop. I've shown that code at the beginning of the chapter, but for convenience I'll reprint it here:

function FindPrimes(lowBound, highBound: integer): integer;var  i: Integer;begin  Result := 0;  for i := lowBound to highBound do    if IsPrime(i) then      Inc(Result);end;

When he calls, for example, FindPrimes(1,10000000), the computer spends a long time doing the calculation during which time only one CPU is busy. That is not surprising given that in any Delphi program only one thread is running by default. If we want to make other CPUs busy too, we have to run multiple threads.

In his case, it ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Delphi GUI Programming with FireMonkey

Delphi GUI Programming with FireMonkey

Andrea Magni
Delphi Cookbook - Third Edition

Delphi Cookbook - Third Edition

Daniele Spinetti, Daniele Teti

Publisher Resources

ISBN: 9781838989118Other