https://github.com/taskflow/work-stealing-queue
A fast work-stealing queue template in C++
https://github.com/taskflow/work-stealing-queue
multithreading parallel-computing parallel-programming work-stealing
Last synced: about 1 month ago
JSON representation
A fast work-stealing queue template in C++
- Host: GitHub
- URL: https://github.com/taskflow/work-stealing-queue
- Owner: taskflow
- License: other
- Created: 2020-02-08T06:10:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T10:50:00.000Z (over 1 year ago)
- Last Synced: 2025-03-30T10:09:05.165Z (about 2 months ago)
- Topics: multithreading, parallel-computing, parallel-programming, work-stealing
- Language: C++
- Homepage:
- Size: 1010 KB
- Stars: 305
- Watchers: 10
- Forks: 39
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Work-Stealing Queue
A fast single-header work-stealing queue template written in modern C++17
# How to Use
A work-stealing queue enables one thread (queue owner) to
push/pop items into/from one end of the queue,
and multiple threads (thieves) to steal items from the other end.
The following example
shows the basic use of [wsq.hpp](wsq.hpp).```cpp
// work-stealing queue of integer numbers
WorkStealingQueue queue;// only one thread can push and pop items from one end
std::thread owner([&] () {
for(int i=0; i<100000000; i=i+1) {
queue.push(i);
}
while(!queue.empty()) {
std::optional item = queue.pop();
}
});// multiple threads can steal items from the other end
std::thread thief([&] () {
while(!queue.empty()) {
std::optional item = queue.steal();
}
});owner.join();
thief.join();
```The library is a single header file.
Simply compile your source with include path to [wsq.hpp](wsq.hpp).# Compile Examples and Unittests
We use cmake to manage the package. We recommand using out-of-source build:
```bash
~$ mkdir build
~$ cd build
~$ cmake ..
~$ make & make test
```# Technical Details
This library implements the work-stealing queue algorithm
described in the paper,
"[Correct and Efficient Work-Stealing for Weak Memory Models](references/ppopp13.pdf),"
published by Nhat Minh Lê,
Antoniu Pop, Albert Cohen, and Francesco Zappa Nardelli
at 2013 ACM Principles and Practice of Parallel Programming (PPoPP).# Robustness
This library is part of the
[Cpp-Taskflow](https://github.com/cpp-taskflow/cpp-taskflow)
project.
It has experienced thousands of tests in both micro-benchmarks
and large-scale real-world parallel applications.