Code Monkey home page Code Monkey logo

work-stealing-queue's Introduction

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.

// work-stealing queue of integer numbers
WorkStealingQueue<int> 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<int> item = queue.pop();
  }
});

// multiple threads can steal items from the other end
std::thread thief([&] () {
  while(!queue.empty()) {
    std::optional<int> item = queue.steal();
  }
});

owner.join();
thief.join();

The library is a single header file. Simply compile your source with include path to wsq.hpp.

Compile Examples and Unittests

We use cmake to manage the package. We recommand using out-of-source build:

~$ 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," 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 project. It has experienced thousands of tests in both micro-benchmarks and large-scale real-world parallel applications.

work-stealing-queue's People

Contributors

charlietsao avatar clin99 avatar tsung-wei-huang avatar twhuang-utah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

work-stealing-queue's Issues

Multiple Porducer/Single Consumer

It would be good if the library support reverse operation such as multiple producers (ie threads) and single consumer. Is that feasable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.