https://github.com/conorwilliams/concurrentdeque
Fast, generalized, implementation of the Chase-Lev lock-free work-stealing deque for C++17
https://github.com/conorwilliams/concurrentdeque
chase-lev concurrent-data-structure lock-free-queue multithreading parallel-computing work-stealing
Last synced: 6 months ago
JSON representation
Fast, generalized, implementation of the Chase-Lev lock-free work-stealing deque for C++17
- Host: GitHub
- URL: https://github.com/conorwilliams/concurrentdeque
- Owner: ConorWilliams
- License: mpl-2.0
- Created: 2021-03-11T08:51:05.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-09-11T08:42:03.000Z (over 4 years ago)
- Last Synced: 2025-06-30T22:06:24.411Z (6 months ago)
- Topics: chase-lev, concurrent-data-structure, lock-free-queue, multithreading, parallel-computing, work-stealing
- Language: C++
- Homepage:
- Size: 1.07 MB
- Stars: 146
- Watchers: 7
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `riften::Deque`
A bleeding-edge lock-free, single-producer multi-consumer, Chase-Lev work stealing deque as presented in the paper "Dynamic Circular Work-Stealing Deque" and further improved in the follow up paper: "Correct and Efficient Work-Stealing for Weak Memory Models".
This implementation is based on:
- https://github.com/taskflow/work-stealing-queue
- https://github.com/ssbl/concurrent-deque
`riften::Deque` places very few constraints on the types which can be placed in the deque (they must be default initializable, trivially destructible and have nothrow move constructor/assignment operators) and has no memory overhead associated with buffer recycling.
## Usage
```C++
// #include
// #include "riften/deque.hpp"
// Work-stealing deque of ints
riften::Deque deque;
// One thread can push and pop items from one end (like a stack)
std::thread owner([&]() {
for (int i = 0; i < 10000; i = i + 1) {
deque.emplace(i);
}
while (!deque.empty()) {
std::optional item = deque.pop();
}
});
// While multiple (any) threads can steal items from the other end
std::thread thief([&]() {
while (!deque.empty()) {
std::optional item = deque.steal();
}
});
owner.join();
thief.join();
```
## CMake
This is a single-header library. Additionally, the library can be installed:
```zsh
mkdir build && cd build
cmake ..
make && make install
```
and then imported into your CMake project by including:
```CMake
find_package(RiftenDeque REQUIRED)
```
in your `CMakeLists.txt` file.
### CPM.cmake
The recommended way to consume this library is through [CPM.cmake](https://github.com/cpm-cmake/CPM.cmake), just add:
```CMake
CPMAddPackage("gh:ConorWilliams/ConcurrentDeque#v1.1.0")
```
to your `CMakeLists.txt` and you're good to go!
## Tests
To compile and run the tests:
```zsh
mkdir build && cd build
cmake ../test
make && make test
```