Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix README.md formatting #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CTPL
====

Modern and efficient C++ Thread Pool Library
## Modern and efficient C++ Thread Pool Library


A thread pool is a programming pattern for parallel execution of jobs, http://en.wikipedia.org/wiki/Thread_pool_pattern.
Expand All @@ -10,7 +10,8 @@ More specifically, there are some threads dedicated to the pool and a container

A thread pool is helpful when you want to minimize time of loading and destroying threads and when you want to limit the number of parallel jobs that run simultanuasly. For example, time consuming event handlers may be processed in a thread pool to make UI more responsive.

Features:
## Features

- standard c++ language, tested to compile on MS Visual Studio 2013 (2012?), gcc 4.8.2 and mingw 4.8.1(with posix threads)
- simple but effiecient solution, one header only, no need to compile a binary library
- query the number of idle threads and resize the pool dynamically
Expand All @@ -23,37 +24,41 @@ Features:
- two variants, one depends on Boost Lockfree Queue library, http://boost.org, which is a header only library


Sample usage
## Sample usage

<code>void first(int id) {
```c++
void first(int id) {
std::cout << "hello from " << id << '\n';
}</code>
}

<code>&#32;&#32;struct Second {
struct Second {
void operator()(int id) const {
std::cout << "hello from " << id << '\n';
}
} second;

<code>void third(int id, const std::string & additional_param) {}</code>


<code>int main () {</code>

<code>&#32;&#32;&#32;&#32;ctpl::thread_pool p(2 /* two threads in the pool */);</code>
void third(int id, const std::string & additional_param) {}

<code>&#32;&#32;&#32;&#32;p.push(first); // function</code>
int main () {
// Create a threadpool with 2 threads
ctpl::thread_pool p(2);

<code>&#32;&#32;&#32;&#32;p.push(third, "additional_param");</code>

<code>&#32;&#32;&#32;&#32;p.push( &#91;&#93; (int id){
std::cout << "hello from " << id << '\n';
}); // lambda</code>

<code>&#32;&#32;&#32;&#32;p.push(std::ref(second)); // functor, reference</code>
// Add regular functions to the threadpool
p.push(first);
p.push(third, "additional_param");

// Add lambdas to the threadpool
p.push( [] (int id){
std::cout << "hello from " << id << '\n';
}); // lambda

<code>&#32;&#32;&#32;&#32;p.push(const_cast&#60;const Second &&#62;(second)); // functor, copy ctor</code>
// functor, reference
p.push(std::ref(second));

<code>&#32;&#32;&#32;&#32;p.push(std::move(second)); // functor, move ctor</code>
// functor, copy constructor
p.push(const_cast<const Second &>(second));

<code>}</code>
// functor, move ctor
p.push(std::move(second));
}
```