This library is a collection of lock-free and lock-based fine-grained algorithms of data structures like maps, queues, list etc. The library contains implementation of well-known data structures and memory reclamation schemas for modern processor architectures. The library is written on C++11.
Supported processor architectures and operating systems (OS) are:
For each lock-free data structure the
CDS library presents several implementation based on published papers. For example, there are several implementations of queue, each of them is divided by memory reclamation schema used. However, any implementation supports common interface for the type of data structure.
To use any lock-free data structure, the following are needed:
boost::atomicor its own atomic implementation
SMR is the main part of lock-free data structs. The SMR solves the problem of safe memory reclamation that is one of the main problem for lock-free programming. The library contains the implementations of several light-weight memory reclamation schemes:
cds::gc::DHPfor more explanation
cds::gc::nogc"GC" for append-only containers that do not support item reclamation.
Many GC requires a support from the thread. The library does not define the threading model you must use, it is developed to support various ones; about incorporating cds library to your threading model see
The main part of lock-free programming is SMR, so-called garbage collector, for safe memory reclamation. The library provides several types of SMR schemes. One of widely used and well-tested is Hazard Pointer memory reclamation schema discovered by M. Micheal and implemented in the library as
cds::gc::HP class. Usually, the application is based on only one type of GC.
In the next example we mean that you use Hazard Pointer
cds::gc::HP - based containers.
First, in your code you should initialize
cds library and Hazard Pointer in
Second, any of your thread should be attached to
After that, you can use
cds lock-free containers safely without any external synchronization.
In some cases, you should work in an external thread. For example, your application is a plug-in for a server that calls your code in a thread that has been created by the server. In this case, you should use persistent mode of garbage collecting. In this mode, the thread attaches to the GC singleton only if it is not attached yet and never call detaching:
The cds is mostly header-only library. Only small part of library related to GC core functionality should be compiled.
External dependenies: the tests depends on:
boost.thread(thread-loal storage support), boost.system
Prerequisites: for building cds library and test suite you need:
PATHenvironment variable should contain full path to Perl binary. Perl is used to generate large dictionary for testing purpose;
BOOST_PATHcontaining full path to
boostroot directory (for example,
Open solution file
cds\projects\vc14\cds.sln with Microsoft VisualStudio 2015. The solution contains
cds project and a lot of test projects. Just build the library using solution.
Warning: the solution depends on
BOOST_PATH environment variable that specifies full path to
boost library root directory. The test projects search
boost libraries in:
All tests are based on googletest framework. The following environment variables specify where to find gtest include and library directories:
GTEST_ROOT- gtest root directory.
$(GTEST_ROOT)/includespecifies full path to gtest include files;
GTEST_LIB64- the path to 64bit gtest library dir;
GTEST_LIB32- the path to 32bit gtest library dir.
For Unix-like systems GCC and Clang compilers are supported. Use GCC 4.8+ compiler or Clang 3.6+ to build cds library with CMake. See accompanying file
/build/cmake/readme.md for more info.
libcdsmust be compiled with -fno-strict-aliasing compiler flag.