Skip to content

Commit 4f0a5ee

Browse files
committed
Add future
1 parent 5147b60 commit 4f0a5ee

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,4 +553,21 @@ sharedMes = "ping";
553553
thread t1(pingPongFn, sharedMes); // start example with 3 concurrent threads
554554
thread t2(pingPongFn, "pong");
555555
thread t3(pingPongFn, "boing");
556+
```
557+
558+
## `future` (thread support library)
559+
```cpp
560+
#include <future> // Include future
561+
function<int(int)> fib = // Create lambda function
562+
[&](int i){
563+
if (i <= 1){
564+
return 1;
565+
}
566+
return fib(i-1)
567+
+ fib(i-2);
568+
};
569+
future<int> fut = // result of async function
570+
async(launch::async, fib, 4); // start async function in other thread
571+
// do some other work
572+
cout << fut.get(); // get result of async function. Wait if needed.
556573
```

0 commit comments

Comments
 (0)