Skip to content

Commit

Permalink
doc: add getting started doc
Browse files Browse the repository at this point in the history
Signed-off-by: Loic Reyreaud <loic.reyreaud@epita.fr>
  • Loading branch information
Loic Reyreaud committed Aug 19, 2018
1 parent c6cc9ee commit 48ad419
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
51 changes: 51 additions & 0 deletions doc/getting_started.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Getting Started
===============

Install
-------

First, you need the :code:`threadpool.hpp` header file. You can simply copy it
into your source tree, or you can install it. To install run the following
commands:

.. code-block:: bash
$ git clone git@github.com:reyreaud-l/threadpool.git
$ cd threadpool
$ mkdir build
$ cd build
$ cmake ..
$ make install
This will make the header available in your system.

First Pool
----------

Let's see a simple use of the threadpool

.. code-block:: c++

#include <iostream>
#include <threadpool/threadpool.hpp>

int main()
{
ThreadPool mypool(1);
auto task = mypool.run([]() { std::cout << "Hello there!" << std::endl; });
std::cout << "General Kenobi!" << std::endl;
task.wait();
}


Note that we instantiate a task and wait for it to make sure the task is ran.
With such a short program, it is possible that mypool will be deleted before a
working is woke up to pick the task and run it. Waiting for the result ensure
the task is ran. It is possible to use this syntax if you don't care about the
return value or want to wait for a task to end

.. code-block:: c++

...
mypool.run([]() { std::cout << "Hello there!" << std::endl; });
...
3 changes: 2 additions & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Welcome to threadpool's documentation!
:maxdepth: 2
:caption: Contents:

threadpool
getting_started




Expand Down
4 changes: 0 additions & 4 deletions doc/threadpool.rst

This file was deleted.

0 comments on commit 48ad419

Please sign in to comment.