Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft's CCR vs Task Parallel Library

Microsoft has at least two different approches to improved support for concurrent operations.

1) Is the Concurrency Coordination Runtime (CCR) which is part of Microsoft Robotics Studio and CCR & DSS Toolkit

2) Task Paralell Library (TPL) (Part of .NET 4.0 and now in Beta 1 release)

I would like to know if anyone has experience with these two different pieces of software and would compare and contrast them?

like image 946
JonnyBoats Avatar asked Apr 15 '09 02:04

JonnyBoats


2 Answers

By and large, both frameworks have complementary but different goals.

The CCR offers primitives for coordination of concurrent processes. Coordination is the glue that makes a bunch of processes work as a whole - so the CCR offers primitives for exchanging messages through so called channels. Processes can wait for a message to arrive on a channel, or a number of channels, or any one of a number of channels and so forth. This is a particular paradigm for coordination of concurrent processes that works well. Note also that is it not free - you have to buy if from Microsoft separately.

The TPL offers primitives and infrastructure to parallellize computations or algorithms semi-automatically. One of the most obvious primitives there is the parallel for loop - looks sort of like a for loop but tries to execute the loop in parallel.

So, if you have a bunch of process that you'd like to coordinate on a higher level than using shared state and locks, use the CCR. If you have a computation-intensive process that you'd like to run efficiently on a multi-core machine, use the TPL.

like image 152
Kurt Schelfthout Avatar answered Sep 28 '22 17:09

Kurt Schelfthout


It's not an either/or scenario. The CCR is a library that supports certain programming patterns. You can intermix CCR and TPL code like this, here is a Parallel.For inside of a Receive delegate:

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Ccr.Core;

namespace Demo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Dispatcher dispatcher = new Dispatcher();
            DispatcherQueue taskQueue = new DispatcherQueue("Demo", dispatcher);
            Port<int> portInt = new Port<int>();
            portInt.Post(Int32.Parse(args[0]));

            Arbiter.Activate(
                taskQueue,
                portInt.Receive(delegate(int count)
                {
                    Parallel.For(0, count, i =>
                    {
                        Console.Write(i.ToString() + " ");
                    });
                }
            ));
        }
    }
}
like image 24
Paul Williams Avatar answered Sep 28 '22 19:09

Paul Williams