Giter Site home page Giter Site logo

threadpool's Introduction

Contents

Introduction
Class view
Performance comparison
Compiler
How to compile
About compilation errors
Tutorial
Future work

Introduction

This is a pure (which means it doesn't depend on any platform) and exception-safety C++ threadpool (so far, there is no standard threadpool in C++).
The goal of this project is to provide a fastest, beautiful and easy-to-use C++ threadpool library.

Class view

Two classes

CThreadPool, including the member function
	thread_id	add(Func &&,Args &&...)
	void		add_and_detach(Func &&,Args &&...)
	size_type	empty() const noexcept
	void		join(thread_id)
	void		join_all()
	bool		joinable(thread_id) const
	size_type	size() const noexcept
	void 		wait_until_all_usable() const
	
CThreadPool_Ret, including the member function
	thread_id	add(Func &&,Args &&...)
	size_type	empty() const noexcept
	Ret			get(thread_id)
	size_type	size() const noexcept
	bool		valid(thread_id) const
	void		wait(thread_id) const
	void 		wait_all() const

Use the CThreadPool_Ret when you want to get the return value of function.
Use the CThreadPool when you don't care the return value of function.
The CThreadPool::add_and_detach is faster (very) than the CThreadPool_Ret::add.

Performance comparison

github search "threadpool language:C++"

About progschj/ThreadPool, see [Compare To Fdhvdu](performance comparison/progschj/README.md#compare-to-fdhvdu).
About henkel/threadpool, somehow, it has memory leak, see [README](performance comparison/henkel/README.md).

P.S. bilash/threadpool needs POSIX support, however, I don't have Unix system. So, there is no comparison result.
P.S. nbsdx/ThreadPool is not thread-safe (as far as 24 commits).
P.S. tghosgor/threadpool11 is not thread-safe (as far as 177 commits and 11 releases).
See the [directory](performance comparison/) for more details.

Compiler

VC++ 14.2
or any compiler which supports C++14

How to compile

You have to download my lib
The directory should be look like

-ThreadPool---header
|            -performance comparison
|            -src
|            -tutorial
|            -LICENSE
|            -README.md
|
-lib----------header
             -src
             -tutorial
             -LICENSE
             -README.md

Don't forget to compile lib/src/CScopeGuard.cpp.

About compilation errors

Q: My compiler doesn't support C++14
A: Get a newer compiler version, such as GCC 5.3.0 or VC++ 14.2 (inside Visual Studio Community 2015 Update 2)

Q: Other problems
A: See How to compile or email me

Tutorial

I provide example.cpp and example_ret.cpp to help you understand how to use this powerful thread pool
To use example.cpp:
g++ -std=c++14 tutorial/example.cpp src/* ../lib/src/CScopeGuard.cpp
To use example_ret.cpp:
g++ -std=c++14 tutorial/example_ret.cpp src/IThreadPoolItemBase.cpp ../lib/src/CScopeGuard.cpp

Future work

replace std::bind in CThreadPool::add, CThreadPool::add_and_detach and CThreadPool_Ret::add with C++17 std::apply
work stealing

threadpool's People

Contributors

fdhvdu avatar

Watchers

James Cloos 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.