X Tutup
The Wayback Machine - https://web.archive.org/web/20200920080407/https://github.com/Ethan13310/Thread-Pool-Cpp
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

README.md

Thread Pool

MIT licensed

C++14 thread pool implementation.

Usage

  • thread_pool(std::size_t thread_count) (Constructor) : Number of worker threads to instantiate.
  • push(Func &&fn, Args &&...args) : Push a new task into the queue.
  • clear() : Remove all pending tasks from the queue.
  • join() : Wait all worker threads to finish. This function is called within the destructor.
  • thread_count() const : Get the number of worker threads.
  • active_count() const : Get the number of active worker threads (ie. the number of threads which have a task assigned).

Example

// Create a thread pool with 4 worker threads
thread_pool pool{ 4 };

// Add a new task into the queue
auto future{ pool.push([](double n, double p) { return std::pow(n, p); }, 2, 12) };

// Get the result from the future
std::cout << future.get() << std::endl;

About

C++14 thread pool implementation

Topics

Resources

License

Releases

No releases published

Packages

No packages published

Languages

You can’t perform that action at this time.
X Tutup