File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -14963,8 +14963,30 @@ There is no explicit locking and both correct (value) return and error (exceptio
14963
14963
14964
14964
##### Example
14965
14965
14966
- ???
14966
+ int read_value(const std::string& filename)
14967
+ {
14968
+ std::ifstream in(filename);
14969
+ in.exceptions(std::ifstream::failbit);
14970
+ int value;
14971
+ in >> value;
14972
+ return value;
14973
+ }
14974
+
14967
14975
14976
+ void async_example()
14977
+ {
14978
+ try
14979
+ {
14980
+ auto v1 = std::async(std::launch::async, read_value, "v1.txt");
14981
+ auto v2 = std::async(std::launch::async, read_value, "v2.txt");
14982
+ std::cout << v1.get() + v2.get() << '\n';
14983
+ }
14984
+ catch (std::ios_base::failure & fail)
14985
+ {
14986
+ // handle exception here
14987
+ }
14988
+ }
14989
+
14968
14990
##### Note
14969
14991
14970
14992
Unfortunately, `async()` is not perfect.
You can’t perform that action at this time.
0 commit comments