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
end); Head over and check out the full blog post with all of the links to info about the new TParallel.For loop in Delphi XE7 Firemonkey.
FMXExpress.com has over 700 tips and tricks for building cross platform apps on Android, IOS, OSX, Windows, and Linux with a single codebase and single UI using the FireMonkey framework found in Delphi and C++Builder.
FMXExpress covers top cross platform secrets for FireMonkey in C++Builder and Delphi XE5, XE6, XE7, XE8, Seattle, Berlin, Tokyo, Rio, and Sydney.