BT

InfoQ Homepage News A Task Parallel Library for Object Pascal and C++

A Task Parallel Library for Object Pascal and C++

Bookmarks

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
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.

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

Community comments

  • 'Unlike Mono ....' ?!?

    by Petar Shomov /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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

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

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.