BT

A Task Parallel Library for Object Pascal and C++

| by Jonathan Allen Follow 635 Followers on Oct 27, 2014. Estimated reading time: 1 minute |

A major feature of RAD Studio XE7 is its Parallel Programming Library. XE7 brings task-based parallelism to a variety of platforms including Windows, OS X, iOS, and Android. Unlike Mono, this tool-chain offers fully native applications on all target platforms.

At the core of the XE7 Parallel Programming Library are tasks and futures. These are available as both interfaces (ITask, IFuture) and classes (TTask, TFuture). These are equivalent to .NET’s Task and Task<T> classes.

When working with discrete operations, tasks and futures are generally used on their own. If you want to parallelize a set of operations, then wrappers come into play. For example, you can abstract the task logic needed to parallelize a for-loop using code such as this:

TParallel.For(1, Max, procedure (I: Integer)
    begin
        if IsPrime (I) then
        TInterlocked.Increment (TotalPrimes);
    end);

For those of you unfamiliar with Object Pascal, the ‘procedure’ keyword creates an anonymous function. This is similar in behavior to VB’s ‘Function’ keyword or C#’s arrow syntax.

Note the use of the TInterlocked.Increment class. This is a platform-agnostic version of the Windows Interlocked.Increment. Without it, the TotalPrimes count may be incorrect due to race conditions. So while this library simplifies parallel coding, the developer is still responsible for ensuring it is done correctly.

A major flaw in the Parallel Programming Library isn’t the code itself, but rather the documentation. Of the 18 classes and types, only seven of them even have a one-line description. While sometimes acceptable for a free/open source library, this is quite unusual for a modern commercial offering.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

'Unlike Mono ....' ?!? by Petar Shomov

Regarding - 'Unlike Mono, this tool-chain offers fully native applications on all target platforms'. I thought mono/xamarin is native on all platforms it supports?

Could you please clarify how is Rad Studio different in 'nativeness' then Mono/Xamarin?

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss
BT