cds  1.6.0
CDS: Concurrent Data Structures library

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.

Supported processor architectures and operating systems (OS) are:

Supported compilers:

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 implement any lock-free data structure, two things are needed:

The main part of lock-free data structs is garbage collecting. The garbage collector (GC) solves the problem of safe memory reclamation that is one of the main problems for lock-free programming. The library contains the implementations of several light-weight memory reclamation schemes:

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 cds::threading.

The main namespace for the library is cds. To see the full list of container's class go to modules tab.

How to build

The cds is mostly header-only library. Only small part of library related to GC core functionality must be compiled. The test projects depends on the following static library from boost:

Windows build

Prerequisites: for building cds library and test suite you need:

Open solution file cds\projects\vcX\cds.sln where vcX - version of Microsoft Visual C++ you use: vc9 for MS VC 2008, vc10 for MS VC 2010 and so on. The solution contains cds project and several 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:

*NIX build

For Unix-like systems GCC and Clang compilers are supported. Use GCC 4.3 (or above) compiler or Clang 3.0 or above to build cds library. The distributive contains makefile and script in build directory. The build/sample directory contains sample scripts for different operating systems and processor architectures. The script supports the following options:

How to use

To use cds lock-free containers based on garbage collectors (GC) provided by library your application must be linked with libcds.

The main part of lock-free programming is garbage collecting for safe memory reclamation. The library provides several types of GC schemes. One of widely used and well-tested one 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 your application uses Hazard Pointer (cds::gc::HP) - based containers. Other GCs (cds::gc::HRC, cds::gc::PTB) are applied analogously.

First, in your code you should initialize cds library and a garbage collector in main function:

#include <cds/init.h> // for cds::Initialize and cds::Terminate
#include <cds/gc/hp.h> // for cds::HP (Hazard Pointer) garbage collector
int main(int argc, char** argv)
// Initialize libcds
// Initialize Hazard Pointer singleton
cds::gc::HP hpGC;
// If main thread uses lock-free containers
// the main thread should be attached to libcds infrastructure
// Now you can use HP-based containers in the main thread
// Terminate libcds

Second, any of your thread should be attached to cds infrastructure.

#include <cds/gc/hp.h>
int myThreadEntryPoint(void *)
// Attach the thread to libcds infrastructure
// Now you can use HP-based containers in the thread
// Detach thread when terminating

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:

#include <cds/gc/hp.h>
int plugin_entry_point()
// Attach the thread if it is not attached yet
if ( !cds::threading::Manager::isThreadAttached() )
// Do some work with HP-related containers

cds 1.6.0 Developed by Maxim Khiszinsky aka khizmax 2007 - 2014
Autogenerated Thu Sep 18 2014 23:19:19 by Doxygen 1.8.8