There was an error while loading. Please reload this page.
1 parent 5147b60 commit 4f0a5eeCopy full SHA for 4f0a5ee
README.md
@@ -553,4 +553,21 @@ sharedMes = "ping";
553
thread t1(pingPongFn, sharedMes); // start example with 3 concurrent threads
554
thread t2(pingPongFn, "pong");
555
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.
573
```
0 commit comments