Git Product home page Git Product logo

dtasks's Introduction

Dumb Task Scheduler

Build Status

This is a "dumb simple" multi-threaded task runner and scheduler library.

Features

  • Thread pool with configurable thread count
  • Executor to enqueue and schedule tasks
    • Enqueue task, obtain future
    • Schedule a number of tasks after a number of associated dependencies (futures) have been completed (signalled)
  • Rethrow the first exception caught, if any
  • Stop/restart execution and queue at any time

Dependencies

  • ktl (via CMake FetchContent)

Usage

Requirements

  • CMake
  • C++20 compiler (and stdlib)

Steps

  1. Clone repo to appropriate subdirectory, say dumb_tasks
  2. Add library to project via: add_subdirectory(dumb_tasks) and target_link_libraries(foo dtasks::dtasks)
  3. Use via: #include <dumb_tasks/executor.hpp>

Example

#include <dumb_tasks/executor.hpp>
#include <ktl/stack_string.hpp>
#include <iostream>
#include <vector>

int main() {
  dts::thread_pool pool;
  dts::executor executor(&pool);
  std::vector<dts::future_t> futures;
  int n{};
  for (int i = 0; i < 5; ++i) {
    auto future = executor.enqueue([n] { std::cout << ktl::stack_string<4>("{} ", n).get(); });
    futures.push_back(std::move(future));
    ++n;
  }
  n = 50;
  std::vector<dts::task_t> tasks;
  for (int i = 0; i < 5; ++i) {
    auto task = [n]() { std::cout << ktl::stack_string<4>("{} ", n).get(); };
    tasks.push_back(task);
    ++n;
  }
  auto future = executor.schedule(tasks, futures);
  future.wait(); 
  std::cout.flush();
  // potential output: 1 0 2 3 4 50 52 51 53 54
}

Contributing

Pull/merge requests are welcome.

dtasks's People

Contributors

karnkaul avatar

Watchers

James Cloos avatar  avatar  avatar

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.