All Projects → Tyler-Hardin → thread_pool

Tyler-Hardin / thread_pool

Licence: other
Thread pool using std::* primitives from C++17, with optional priority queue/greenthreading for POSIX.

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to thread pool

goethe
Threading and Caching Utilities for golang
Stars: ✭ 30 (-59.46%)
Mutual labels:  thread-pool
util
封装了一些Java常用的功能
Stars: ✭ 19 (-74.32%)
Mutual labels:  thread-pool
thread-pool
A modern thread pool implementation based on C++20
Stars: ✭ 104 (+40.54%)
Mutual labels:  thread-pool
akali
C++ Common Library for Windows, Linux.
Stars: ✭ 34 (-54.05%)
Mutual labels:  thread-pool
leek
Distributed task redisqueue(最简单python分布式函数调度框架)
Stars: ✭ 60 (-18.92%)
Mutual labels:  thread-pool
java-sdk
一些常用的java sdk和工具类(日期工具类,分布式锁,redis缓存,二叉树,反射工具类,线程池,对称/非对称/分段加解密,json序列化,http工具,雪花算法,字符串相似度,集合操作工具,xml解析,重试Retry工具类,Jvm监控等)
Stars: ✭ 26 (-64.86%)
Mutual labels:  thread-pool
Lazy
Light-weight header-only library for parallel function calls and continuations in C++ based on Eric Niebler's talk at CppCon 2019.
Stars: ✭ 93 (+25.68%)
Mutual labels:  thread-pool
Mgx
🌈 A high performance network framework written in c++ (support tcp and http)
Stars: ✭ 15 (-79.73%)
Mutual labels:  thread-pool
notes
📓 Notes related to Computer Science stuff.
Stars: ✭ 15 (-79.73%)
Mutual labels:  concepts
hellhound
A set of libraries to create asynchronous, high performance, scalable and simple application.
Stars: ✭ 33 (-55.41%)
Mutual labels:  thread-pool
NamingThings
Content on tips, tricks, advice, practices for naming things in in software/technology
Stars: ✭ 31 (-58.11%)
Mutual labels:  concepts
programming-with-cpp20
Companion source code for "Programming with C++20 - Concepts, Coroutines, Ranges, and more"
Stars: ✭ 142 (+91.89%)
Mutual labels:  concepts
LFTPool
Lock-Free Thread Pool
Stars: ✭ 69 (-6.76%)
Mutual labels:  thread-pool
penguinV
Simple and fast C++ image processing library with focus on heterogeneous systems
Stars: ✭ 110 (+48.65%)
Mutual labels:  thread-pool
TaskManager
A C++14 Task Manager / Scheduler
Stars: ✭ 81 (+9.46%)
Mutual labels:  thread-pool
thread-pool
BS::thread_pool: a fast, lightweight, and easy-to-use C++17 thread pool library
Stars: ✭ 1,043 (+1309.46%)
Mutual labels:  thread-pool
data-science-learning
📊 All of courses, assignments, exercises, mini-projects and books that I've done so far in the process of learning by myself Machine Learning and Data Science.
Stars: ✭ 32 (-56.76%)
Mutual labels:  concepts
dw-thread-pool
A simple, header-only, dependency-free, C++ 11 based ThreadPool library.
Stars: ✭ 26 (-64.86%)
Mutual labels:  thread-pool
haxe-concurrent
A haxelib for basic platform-agnostic concurrency support
Stars: ✭ 69 (-6.76%)
Mutual labels:  thread-pool
not-enough-standards
A modern header-only C++ library that provides platform-independent utilities.
Stars: ✭ 197 (+166.22%)
Mutual labels:  thread-pool

thread_pool

Thread pool using std::* primitives from C++11. Also includes a class for a priority thread pool.

Requires concepts and C++17, including constexpr-if. Currently only GCC 7.0+ is sufficient. Use -std=c++17 -fconcepts to compile. The priority thread pool is only supported on POSIX/-like systems. But it's still easy to use the normal pool on non-POSIX; just don't compile priority_thread_pool.cpp or include the header.

If GCC 6.2 is prefered, revision 65879c9 is compatible. For just C++11, use 8bdfb9b. 5ea01d0 was the latest to support <= C++14.

The priority pool has the same API as described below, accept it has an int parameter first for the priority of the task. E.g. pool.async(5, func, arg1, arg2) for priority 5.

An example that computes the primality of 2 to 10,000 using 8 threads:

#include "thread_pool.hpp"

#include <iostream>
#include <list>
#include <utility>

using namespace std;

// Return the integer argument and a boolean representing its primality.
// We need to return the integer because the loop that retrieves results doesn't know which integer corresponds to which future.
pair<int, bool> is_prime(int n){
  for(int i = 2;i < n;i++)
    if(n % i == 0)
      return make_pair(i, false);
  return make_pair(n, true);
}

int main(){
  thread_pool pool(8);                   // Contruct a thread pool with 8 threads.
  list<future<pair<int, bool>>> results;
  for(int i = 2;i < 10000;i++){
  	// Add a task to the queue.
    results.push_back(pool.async(is_prime, i));
  }
  
  for(auto i = results.begin();i != results.end();i++){
    pair<int, bool> result = i->get();  // Get the pair<int, bool> from the future<...>
    cout << result.first << ": " << (result.second ? "is prime" : "is composite") << endl;
  }
  return 0;
}

thread_pool::async is a templated method that accepts any std::function and arguments to pass to the function. It returns a std::future<Ret> where Ret is the return type of the aforementioned std::function.

To submit a task: future<Ret> fut(pool.async(func, args...));.

To wait on fut to complete: Ret result = fut.get();

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].