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
1496314963
1496414964##### Example
1496514965
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+
1496714975
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+
1496814990##### Note
1496914991
1497014992Unfortunately, `async()` is not perfect.
You can’t perform that action at this time.
0 commit comments