SkillAgentSearch skills...

AsyncMulticastDelegate

Asynchronous Multicast Delegates in C++

Install / Use

/learn @endurodave/AsyncMulticastDelegate

README

Asynchronous Multicast Delegates in C++

A C++ standards compliant delegate library capable of targeting any callable function synchronously or asynchronously.

⚠️ Deprecated Repository

Warning: This repository is no longer maintained. Please use the modern delegate library in link below.

New Repository

DelegateMQ - Invoke any C++ callable function synchronously, asynchronously, or on a remote endpoint..

Table of Contents

Preface

Originally published on CodeProject at: <a href="http://www.codeproject.com/Articles/1160934/Asynchronous-Multicast-Delegates-in-Cplusplus"><strong>Asynchronous Multicast Delegates in C++</strong></a>

Related repositories

  • <a href="https://github.com/endurodave/IntegrationTestFramework">Integration Test Framework using Google Test and Delegates</a> - a multi-threaded C++ software integration test framework using Google Test and Delegate libraries.

Library Comparison

<p>Asynchronous function invocation allows for easy movement of data between threads. The table below summarizes the various asynchronous function invocation implementations available in C and C++.</p>

| Repository | Language | Key Delegate Features | Notes | |-------------------------------------------------------------------------------------------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | <a href="https://github.com/endurodave/AsyncMulticastDelegateModern">AsyncMulticastDelegateModern</a> | C++17 | * Function-like template syntax<br> * Any delegate target function type (member, static, free, lambda)<br> * N target function arguments<br> * N delegate subscribers<br> * Variadic templates<br> * Template metaprogramming | * Most generic implementation<br> * Lowest lines of source code<br> * Slowest of all implementations<br> * Optional fixed block allocator support<br> * No remote delegate support<br> * Complex metaprogramming | | <a href="https://github.com/endurodave/AsyncMulticastDelegateCpp17">AsyncMulticastDelegateCpp17</a> | C++17 | * Function-like template syntax<br> * Any delegate target function type (member, static, free, lambda)<br> * 5 target function arguments<br> * N delegate subscribers<br> * Optional fixed block allocator<br> * Variadic templates | * Selective compile using constexpr<br> * Avoids complex metaprogramming<br> * Faster than AsyncMulticastDelegateModern<br> * No remote delegate support | | <a href="https://github.com/endurodave/AsyncMulticastDelegateCpp11">AsyncMulticastDelegateCpp11</a> | C++11 | * Function-like template syntax<br> * Any delegate target function type (member, static, free, lambda)<br> * 5 target function arguments<br> * N delegate subscribers<br> * Optional fixed block allocator | * High lines of source code<br> * Highly repetitive source code | | <a href="https://github.com/endurodave/AsyncMulticastDelegate">AsyncMulticastDelegate</a> | C++03 | * Traditional template syntax<br> * Any delegate target function type (member, static, free)<br> * 5 target function arguments<br> * N delegate subscribers<br> * Optional fixed block allocator | * High lines of source code<br> * Highly repetitive source code | | <a href="https://github.com/endurodave/AsyncCallback">AsyncCallback</a> | C++ | * Traditional template syntax<br> * Delegate target function type (static, free)<br> * 1 target function argument<br> * N delegate subscribers | * Low lines of source code<br> * Most compact C++ implementation<br> * Any C++ compiler | | <a href="https://github.com/endurodave/C_AsyncCallback">C_AsyncCallback</a> | C | * Macros provide type-safety<br> * Delegate target function type (static, free)<br> * 1 target function argument<br> * Fixed delegate subscribers (set at compile time)<br> * Optional fixed block allocator | * Low lines of source code<br> * Very compact implementation<br> * Any C compiler |

Introduction

<p>Nothing seems to garner the interest of C++ programmers more than delegates. In other languages, the delegate is a first-class feature so developers can use these well-understood constructs. In C++, however, a delegate is not natively available. Yet that doesn&rsquo;t stop us programmers from trying to emulate the ease with which a delegate stores and invokes any callable function.</p> <p>Delegates normally support synchronous executions, that is, when invoked, the bound function is executed within the caller&rsquo;s thread of control. On multi-threaded applications, it would be ideal to specify the target function and the thread it should execute on without imposing function signature limitations. The library does the grunt work of getting the delegate and all argument data onto the destination thread. The idea behind this article is to provide a C++ delegate library with a consistent API that is capable of synchronous and asynchronous invocations on any callable function.</p> <p>The features of the delegate library are:</p> <ol> <li><strong>Any Compiler</strong> &ndash; standard C++ code for any compiler without weird hacks</li> <li><strong>Any Function</strong> &ndash; invoke any callable function: member, static, or free</li> <li><strong>Any Argument Type</strong> &ndash; supports any argument type: value, reference, pointer, pointer to pointer</li> <li><strong>Multiple Arguments</strong> &ndash; supports multiple function arguments</li> <li><strong>Synchronous Invocation</strong> &ndash; call the bound function synchronously</li> <li><strong>Asynchronous Invocation</strong> &ndash; call the bound function asynchronously on a client specified thread</li> <li><strong>Blocking Asynchronous Invocation</strong> - invoke asynchronously using blocking or non-blocking delegates</li> <li><strong>Smart Pointer Support</strong> - bind an instance function using a raw object pointer or <code>std::shared_ptr</code></li> <li><strong>Automatic Heap Handling</strong> &ndash; automatically copy argument data to the heap for safe tra

Related Skills

View on GitHub
GitHub Stars5
CategoryDevelopment
Updated1y ago
Forks2

Languages

C++

Security Score

75/100

Audited on Feb 18, 2025

No findings