Gungnir is a modern and easy-to-use C++ library for concurrent task scheduling, inspired by the Grand Central Dispatch (GCD) framework for Objective-C/Swift. It is made with speed, ease of use, and full compatibility with the C++11 standard in mind.
Features:
- Fully compatible with the C++11 standard. Designed to be used with C++11's callable objects and lambda expressions.
- Strives for speed and efficiency with thread pools.
- Reduces boilerplate code needed to manage threads, task queues, etc.
- Light-weight header-only library.
(Gungnir is Odin's magic spear that always hits its mark. This library is named after the spear, in the hope of having the same power and reliability.)
Gungnir is a header-only library, so no linking is required. In order to install Gungnir to the standard system include path (usually /usr/local/include
), run:
$ make check # optional but recommended
$ make install
Alternatively, just drop it in your project.
The task pool functionality is implemented by the gungnir::TaskPool
class. You can submit tasks to be executed to a task pool with one of the dispatch
member functions of the gungnir::TaskPool
class:
// using std::future;
// using std::once_flag;
// using std::vector;
// template <typename R> using Task = std::function<R()>;
void dispatch(const Task<void> &task);
future<R> dispatch(const Task<R> &task);
void dispatch(Iter first, Iter last);
vector<future<R>> dispatch(Iter first, Iter last);
void dispatchSync(Iter first, Iter last);
vector<R> dispatchSync(Iter first, Iter last);
void dispatchSerial(Iter first, Iter last);
vector<future<R>> dispatchSerial(Iter first, Iter last);
void dispatchOnce(once_flag &flag, const Task<void> &task);
Some utility functions in the gungnir
namespace make it easier to work with std::future
and std::shared_future
:
// using std::shared_future;
void onSuccess(const shared_future<R> &future, const S &callback);
void onFailure(const shared_future<R> &future, const F &callback);
void onComplete(const shared_future<R> &future, const S &success, const F &failure);
Thanks to Cameron for the blazing fast moodycamel::ConcurrentQueue.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.