From 4f0a5ee779569df6cf14de1e040cc7625dfebfe7 Mon Sep 17 00:00:00 2001 From: Morten Nobel-Joergensen Date: Wed, 1 Aug 2018 10:28:08 +0200 Subject: [PATCH] Add future --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 3a4e2c7..eac532c 100644 --- a/README.md +++ b/README.md @@ -553,4 +553,21 @@ sharedMes = "ping"; thread t1(pingPongFn, sharedMes); // start example with 3 concurrent threads thread t2(pingPongFn, "pong"); thread t3(pingPongFn, "boing"); +``` + +## `future` (thread support library) +```cpp +#include // Include future +function fib = // Create lambda function + [&](int i){ + if (i <= 1){ + return 1; + } + return fib(i-1) + + fib(i-2); + }; +future fut = // result of async function + async(launch::async, fib, 4); // start async function in other thread +// do some other work +cout << fut.get(); // get result of async function. Wait if needed. ``` \ No newline at end of file