Skip to content

ryanclouser/thread_pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple C++14 Thread Pool

Build Status Donate with Bitcoin Donate with Ethereum Donate with Litecoin

Creates an arbitrary number of threads for which work can be done on. Certain tasks can be completed asynchronously for which a thread pool can be used for. This particular implementation uses the future/promise model added in C++11. A C++14 compatible compiler is required for make_unique.

Usage

#include "thread_pool.h"

int my_work_function(int arg)
{
	return arg;
}

// Create the thread pool. By default the thread count is the hardware concurrency value.
thread_pool<int> pool;

// Create some work. Pass any function arguments to the bind call.
std::future<int> future = pool.push(std::bind(&my_work_function, 1));

// Wait for the work to be completed
int result = future.get();

If the thread pool object goes out of scope, all threads will be stopped.

License

MIT

About

C++14 Thread Pool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages