David Intersimone from Embarcadero has a blog post up which highlights more information about the new parallel programming library which ships with Delphi XE7 Firemonkey. The parallel functions work across all platforms (Android, IOS, OSX, and Windows). From what I understand about the library it has a built in thread pool which the various functions use on the back end to reduce resource usage. There are three blog posts which David I. references by Stephen Ball from Embarcadero where he demonstrates TParallel, TTask, and IFuture. Basically what TParallel.For probably does is take the function that you pass to it and spawn it off in it’s own separate thread. Each time the loop iterates it spawns off a new thread until I assume there is one thread for each CPU (for example 4 threads for a 4 CPU mobile device). Once the work in a thread is complete it goes back into the pool for use later. If you have Delphi XE5 or Delphi XE6 you can check out this custom parallel option. I tested the Conway Game Of Life demo that comes with Delphi XE7 and with parallel mode on it did go at 4X the speed on a 4 CPU X86 machine. I also tested just the straight TParallel.For loop with adding items to a TListView (which you should not do). It did work but it was not thread safe. Here is the sample from Stephen Bell’s blog post (notice how it uses TInterlocked.Increment to increment a number in parallel in a thread safe fashion):
TParallel.For(1, Max, procedure (I: Integer)
if IsPrime (I) then
Fast Threaded Parallel For Loop In Delphi XE7 Firemonkey On Android, IOS, Windows, And OSX by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Tokyo Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.