From dcf09b5d528c3aac14fdcbe93b0f24ce10207d6b Mon Sep 17 00:00:00 2001 From: Paul T Date: Fri, 26 Apr 2024 10:38:10 -0400 Subject: [PATCH] docs: add new snippet to README for `wait_for_tasks()` --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 05c3ff5..8eae41d 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,21 @@ auto result = pool.enqueue([](int value) -> int { /*...your task...*/ return val auto value = result.get(); ``` +Enqueue tasks and wait for them to complete: + +```cpp +dp::thread_pool pool(4); + +// add tasks, in this case without caring about results of individual tasks +pool.enqueue_detach([](int value) { /*...your task...*/ }, 34); +pool.enqueue_detach([](int value) { /*...your task...*/ }, 37); +pool.enqueue_detach([](int value) { /*...your task...*/ }, 38); +pool.enqueue_detach([](int value) { /*...your task...*/ }, 40); + +// wait for all tasks to complete +pool.wait_for_tasks(); +``` + You can see other examples in the `/examples` folder. ## Benchmarks