libcppa  Version 0.1
libcppa
Author:
Dominik Charousset <dominik.charousset (at) haw-hamburg.de>

Introduction

This library provides an implementation of the actor model for C++. It uses a network transparent messaging system to ease development of both concurrent and distributed software using C++.

libcppa uses a thread pool to schedule actors by default. A scheduled actor should not call blocking functions. Individual actors can be spawned (created) with a special flag to run in an own thread if one needs to make use of blocking APIs.

Writing applications in libcppa requires a minimum of gluecode. You don't have to derive a particular class to implement an actor and each context is an actor. Even main is implicitly converted to an actor if needed, as the following example shows:

It's recommended to read at least the message handling section of this documentation.

Hello World Example

#include <string>
#include <iostream>
#include "cppa/cppa.hpp"

using namespace cppa;

void echo_actor()
{
    // wait for a message
    receive
    (
        // invoke this lambda expression if we receive a string
        on<std::string>() >> [](const std::string& what)
        {
            // prints "Hello World!"
            std::cout << what << std::endl;
            // replies "!dlroW olleH"
            reply(std::string(what.rbegin(), what.rend()));
        }
    );
}

int main()
{
    // create a new actor that invokes the function echo_actor
    auto hello_actor = spawn(echo_actor);
    // send "Hello World!" to our new actor
    // note: libcppa converts string literals to std::string objects
    send(hello_actor, "Hello World!");
    // wait for a response and print it
    receive
    (
        on<std::string>() >> [](const std::string& what)
        {
            // prints "!dlroW olleH"
            std::cout << what << std::endl;
        }
    );
    // wait until all other actors we've spawned are done
    await_all_others_done();
    // done
    return 0;
}

Getting Started

To build libcppa, you need GCC >= 4.6, Automake and the Boost.Thread library.

The usual build steps on Linux and Mac OS X are:

Use ./configure --help if the script doesn't auto-select the correct GCC binary or doesn't find your Boost.Thread installation.

Windows is not supported yet, because MVSC++ doesn't implement the C++11 features needed to compile libcppa.