Laughably simple Actor concurrency framework for C++20

Overview

Light Actor Framework

Concurrency is a breeze. Also a nightmare, if you ever used synchronization techniques. Mostly a nightmare, though. This tiny library allows you to forego sync primitives in favor of object-oriented concurrent actors, executing independently from each other in parallel and receiving messages to react to - one at a time each.

Take a listen.

Quick feature rundown

Here is a short taste.

(); for(int i = 0; i < 50; ++i) { // Fifty concurrent messages! counter.Bang(&Counter::Increment); } // How far has the counter come so far? Ask(counter, &Counter::Increment) ->AndThen([](int there) { std::cout << "So far, he's at " << there << std::endl; }); } }; int main() { // Let a set of three OS threads do the message processing. ActorContext acts{3}; // Just create an actor like this. Even with arguments, // if you want to. And if the constructor allows it. auto user = acts.Make (); // Done and done. user.Bang(&User::PlayAround); std::cout << "Meanwhile, main thread sips coffee." << std::endl; } ">
#include <iostream>
#include "Actor.inl"
using namespace laugh;

struct Counter: Actor
{
    int i = 0;
    int Increment() { return ++i; }
};

struct User: Actor
{
    void PlayAround()
    {
        auto counter = Self().Make
     ();
        
     for(
     int i = 
     0; i < 
     50; ++i)
        {
            
     // Fifty concurrent messages!
            counter.
     Bang(&Counter::Increment);
        }
        
        
     // How far has the counter come so far?
        
     Ask(counter, &Counter::Increment)
            ->
     AndThen([](
     int there)
        {
            std::cout << 
     "So far, he's at " << there
                      << std::endl;
        });
    }
};


     int 
     main()
{
    
     // Let a set of three OS threads do the message processing.
    ActorContext acts{
     3};
    
     // Just create an actor like this. Even with arguments,
    
     // if you want to. And if the constructor allows it.
    
     auto user = acts.
     Make
     
      ();
    
    
      // Done and done.
    user.
      Bang(&User::PlayAround);
    
    std::cout << 
      "Meanwhile, main thread sips coffee." << std::endl;
}
     
    

For more information on actors as concurrency units, you'll find plenty on the internet. A good place to get to know actors is Akka, which this project is trying to ape a bit (and fail horribly at it).

Build and requirements

You'll need a fairly compliant C++20 compiler and CMake. For generating the documentation, Doxygen will be necessary.

I have tested this on Clang 13.0.0 and g++-11 on an Apple macOS machine, but I'm confident that this project will compile without any hassle on the vc++ compiler as well, since this project only depends on the standard library and the concurrentqueue module, which is itself C++11 compliant.

Note that Apple Clang 13.0.0 will not compile this as of October 14, 2021, and neither will all Clang compilers of version 12 and lower; on a Macintosh I recommend getting a fresh Clang 13.0.0 build and doing:

# If you're using homebrew, great! Easy-peasy.
brew install llvm doxygen

To build the project and examples, do

# Clone the repo.
git clone https://github.com/tyckesak/laugh
cd laugh

# If you don't have a recent enough C++20 compiler in your $PATH, append
# the CMake flag '-DCMAKE_CXX_COMPILER=«Path to compiler»'
cmake .

# Then do
cmake --build .

For installing the library and the dependency headers, do

cmake --install .

To build the docs, do

cmake --build . --target docs

To re-download the concurrentqueue module, do

# Might need to do this if the compiler can't find the
# concurrentqueue headers.
cmake --build . --target concurrentqueue

The examples and documentation will tell you the rest.

Why that name?

I thought I would do a quick sketch of what a code-light C++ actor framework would look like, and it started to become something quite usable. The contraction of "Light Actor Framework" would be LAF, spoken quickly it eventually turned into "laugh", which turned out to be fitting because this project is laughably small, and easy to grasp and use.

Thanks

@cameron314 and contributors on making a concurrent queue that really stands out!

You might also like...
Yet Another Concurrency Library

YACLib YACLib (Yet Another Concurrency Library) is a C++ library for concurrent tasks execution. Documentation Install guide About dependencies Target

Task System presented in
Task System presented in "Better Code: Concurrency - Sean Parent"

task_system task_system provides a task scheduler for modern C++. The scheduler manages an array of concurrent queues A task, when scheduled, is enque

Deadlockempire.github.io - The Deadlock Empire: Slay dragons, learn concurrency!

The Deadlock Empire A game that teaches locking and concurrency. It runs on https://deadlockempire.github.io. Contributing We gladly welcome all contr

Libgo - Go-style concurrency in C++11
Libgo - Go-style concurrency in C++11

libgo libgo -- a coroutine library and a parallel Programming Library Libgo is a stackful coroutine library for collaborative scheduling written in C+

The RaftLib C++ library, streaming/dataflow concurrency via C++ iostream-like operators

RaftLib is a C++ Library for enabling stream/data-flow parallel computation. Using simple right shift operators (just like the C++ streams that you wo

A task scheduling framework designed for the needs of game developers.

Intel Games Task Scheduler (GTS) To the documentation. Introduction GTS is a C++ task scheduling framework for multi-processor platforms. It is design

High Performance Linux C++ Network Programming Framework based on IO Multiplexing and Thread Pool

Kingpin is a C++ network programming framework based on TCP/IP + epoll + pthread, aims to implement a library for the high concurrent servers and clie

Elle - The Elle coroutine-based asynchronous C++ development framework.
Elle - The Elle coroutine-based asynchronous C++ development framework.

Elle, the coroutine-based asynchronous C++ development framework Elle is a collection of libraries, written in modern C++ (C++14). It contains a rich

KRATOS Multiphysics (
KRATOS Multiphysics ("Kratos") is a framework for building parallel, multi-disciplinary simulation software

KRATOS Multiphysics ("Kratos") is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.

Owner
Josip Palavra
Josip Palavra
An implementation of Actor, Publish-Subscribe, and CSP models in one rather small C++ framework. With performance, quality, and stability proved by years in the production.

What is SObjectizer? What distinguishes SObjectizer? SObjectizer is not like TBB, taskflow or HPX Show me the code! HelloWorld example Ping-Pong examp

Stiffstream 299 Sep 14, 2022
Async++ concurrency framework for C++11

Async++ Async++ is a lightweight concurrency framework for C++11. The concept was inspired by the Microsoft PPL library and the N3428 C++ standard pro

Amanieu d'Antras 1.1k Sep 23, 2022
Concurrency Kit 2.1k Sep 30, 2022
The C++ Standard Library for Parallelism and Concurrency

Documentation: latest, development (master) HPX HPX is a C++ Standard Library for Concurrency and Parallelism. It implements all of the corresponding

The STE||AR Group 1.9k Oct 3, 2022
The libdispatch Project, (a.k.a. Grand Central Dispatch), for concurrency on multicore hardware

Grand Central Dispatch Grand Central Dispatch (GCD or libdispatch) provides comprehensive support for concurrent code execution on multicore hardware.

Apple 2.2k Oct 5, 2022
Go-style concurrency in C

LIBMILL Libmill is a library that introduces Go-style concurrency to C. Documentation For the documentation check the project website: http://libmill.

Martin Sustrik 2.6k Sep 30, 2022
A header-only C++ library for task concurrency

transwarp Doxygen documentation transwarp is a header-only C++ library for task concurrency. It allows you to easily create a graph of tasks where eve

Christian Blume 589 Sep 25, 2022
Modern concurrency for C++. Tasks, executors, timers and C++20 coroutines to rule them all

concurrencpp, the C++ concurrency library concurrencpp is a tasking library for C++ allowing developers to write highly concurrent applications easily

David Haim 1.1k Oct 4, 2022
HPX is a C++ Standard Library for Concurrency and Parallelism

HPX is a C++ Standard Library for Concurrency and Parallelism. It implements all of the corresponding facilities as defined by the C++ Standard. Additionally, in HPX we implement functionalities proposed as part of the ongoing C++ standardization process. We also extend the C++ Standard APIs to the distributed case.

The STE||AR Group 1.9k Oct 3, 2022
Complementary Concurrency Programs for course "Linux Kernel Internals"

Complementary Programs for course "Linux Kernel Internals" Project Listing tpool: A lightweight thread pool. tinync: A tiny nc implementation using co

null 228 Sep 26, 2022