Skip to content

Commit

Permalink
Update README.md and a bit of cleaning.
Browse files Browse the repository at this point in the history
  • Loading branch information
geru-scotland committed Jul 10, 2023
1 parent 941a95a commit 97cfd20
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
35 changes: 17 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,40 @@ make
```

## Basic usage
Include `include/ThreadPool.h` and create a `ThreadPool` object by specifying the number of threads you want to use. Then you can add tasks using the `AddTask()` or `AddTaskWithCallback()` functions. The `Examples` mentioned here refers to a namespace containing some sample functions and methods.
Include `include/ThreadPool.h` and create a `ThreadPool` object by specifying the number of threads you want to use. Then you can add tasks using the overloaded `CreateTask()` method from the pool object. The `Examples` mentioned here refers to a namespace containing some trivial sample functions and methods.

```cpp
ThreadPool tpl(std::thread::hardware_concurrency());
// Create a unique pointer to the pool
std::unique_ptr<ThreadPool> pool = std::make_unique<ThreadPool>(std::thread::hardware_concurrency());

// Shared pointer for the tasks:
std::shared_ptr<Task> task1, task2, task3, task4;
```

- **Example 1**:

```cpp
Task task1;
task1(normalFunction, normalCallback);
pool.AddTask(std::move(task1));
task1 = pool->CreateTask(normalFunction, normalCallback);
```
- **Example 2**:
```cpp
Task task2;
task2(
[](){
printf("\n Lambda main function \n");
},
[]() {
printf("\n Lambda callback \n");
}
);
pool.AddTask(std::move(task2));
task2 = pool->CreateTask(
[](){
printf("\n Lambda main function \n");
},
[]() {
printf("\n Lambda callback \n");
}
);
```

- **Example 3**:
```cpp
std::shared_ptr<Task> task3 = std::make_shared<Task>();
(*task3)(normalFunction, normalCallback);
pool.AddTask((*task3));
std::tuple<int, int, int> args = std::make_tuple(2, 555, 999);
task3 = pool->CreateTask(normalFunctionParams, normalCallbackParams, args);

```
Expand Down
7 changes: 2 additions & 5 deletions examples/examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@

int main() {

std::unique_ptr<ThreadPool> pool = std::make_unique<ThreadPool>(std::thread::hardware_concurrency());
std::shared_ptr<Task> task1, task2, task3, task4;
/**
* Some basic usage examples.
*
* These are merely illustrative, it can be used as one see fit.
*/

std::unique_ptr<ThreadPool> pool = std::make_unique<ThreadPool>(std::thread::hardware_concurrency());
std::shared_ptr<Task> task1, task2, task3, task4;

/**
* Example 1:
* Note: by using std::move(task1) object value renders undefined
* Therefore, the variable task1 should not be used.
*/
task1 = pool->CreateTask(normalFunction, normalCallback);

Expand Down
2 changes: 0 additions & 2 deletions include/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class ThreadPool {
ConditionVariable cv_;
ThreadIdMap threadIdMap_;

// TODO: pending tasks (map based on dependencies), task queue and completed tasks hash map
// The completed tasks, should be accessible by the user.
/**
* @brief EmplaceTaskImpl function template.
*
Expand Down

0 comments on commit 97cfd20

Please sign in to comment.