This is a bare-bones implementation of the Concurrency TS. A simple if terse documentation is available here.
This implementation provides the following abstractions.
future
withthen continuations
, correspondingpromise
(concurrencyts::future
infuture.h
).- An implementation of
async
that returnsfuture
s of the above kind (concurrencyts::async
infuture.h
). when_all
for waiting on multiple futures till all are set (concurrencyts::when_all
infuture.h
).when_any
akin towhen_all
but signaled as soon as any one future is ready.latch
for waiting till N threads have signaled the latch object (concurrencyts::latch
inlatch.h
).barrier
andflex_barrier
for upto N threads to block till all N have arrived (concurrencyts::barrier
andconcurrencyts::flex_barrier
inbarrier.h
). Onlyarrive_and_wait
is implemented, whilearrive_and_drop
is missing.
The rest of the abstractions are absent. While I intend to add them, I don't have a fixed schedule for doing so.
You can use this library with a compiler that supports C++14 or later. It will possibly work with C++11 with minor modifications (change the std::result_of_t<...>
s to std::result_of<...>::type
. We don't use any mostrosity beyond simple GNUMake for building. It has been tested with g++/libstdc++ as well as clang++/libc++ on Linux. It works unchanged with C++17 and C++20.
The library is entirely header-only, and doesn't use any virtual functions, etc. Thus in order to use the future-related functionality, you just include the header future.h
, and get all symbols from the namespace concurrencyts
. Likewise with the other headers.
If you would rather use the std::experimental
namespace, just #include "concurrencyts.h"
. Don't include any other header individually.
You can check example usages of the abstractions by looking at the corresponding .cc
files. You can also build and run them using:
make bin/future
make bin/latch
make bin/barrier
There are no formal unit tests, but I intend to add them soon.