C++ code that rocks !

Visual C++ introduces PPL (Parallel Pattren Library) to provide a clean and safe way to do parallel programming.
Exemple, by the code….

// ProjectBuild.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "..\..\concrtextras\ppltasks.h"
using namespace std;
using namespace Concurrency::samples;
struct Project
{
string Name;
};
int Build(const Project& project)
{
printf("Start building project '%s'\n", project.Name.c_str());
Sleep(1000);
printf("End building project '%s'\n", project.Name.c_str());
return 0;
}
void main()
{
Project A = {"A"}; // A B
Project B = {"B"}; // / \ /
Project C = {"C"}; // C D
Project D = {"D"}; //
task<void> a([=]() {
Build(A);
});
task<void> b([=]() {
Build(B);
});
// Build C after A
auto c = a.continue_with([=]() {
Build(C);
});
// Build D after both A and B
auto d = (a && b).continue_with([=]() {
Build(D);
});
(c && d).wait();
}

Christophe Pichaud | .NET Rangers
MCSD, MCSD.NET, MCTS .NET 2.0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: