Skip to content
forked from Fdhvdu/ThreadPool

A fastest, exception-safety and pure C++17 thread pool.

License

Notifications You must be signed in to change notification settings

fysu/ThreadPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contents

Introduction
Class view
Performance comparison
Compiler
How to compile
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.
CThreadPool::add_and_detach is faster (very) than CThreadPool_Ret::add.

Performance comparison

progschj/ThreadPool, see Comparison.
Tyler-Hardin/thread_pool, see Comparison.
P.S. bilash/threadpool, I don't want to test a C-like code.
P.S. nbsdx/ThreadPool cannot pass testing, see README.
P.S. philipphenkel/threadpool cannot pass testing, see README.
P.S. tghosgor/threadpool11 cannot pass testing, see README.
See the directory for more details.

Compiler

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

How to compile

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

├── lib
│   ├── header
│   ├── LICENSE
│   ├── README.md
│   ├── src
│   └── tutorial
└── ThreadPool
    ├── comparison
    ├── header
    ├── LICENSE
    ├── README.md
    ├── src
    └── tutorial

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

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

About

A fastest, exception-safety and pure C++17 thread pool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 97.6%
  • Makefile 2.4%