std::future<int> f_int = make_dummy_future(42); int i = f_int.get() // f_int.then([](std::future<int> i){/* deal with it */}) //
void resumable_function(int i) async
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
std::future.
resumable . await "" future, . await (, , "!").
. await - std::future, . , Hartmut Kaiser - :
std::future<uint64_t> fibonacci(uint64_t n) async { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs = std::async(&fibonacci, n-1); std::future<uint64_t> rhs = fibonacci(n-2); return await lhs + await rhs; }
resumable . lhs std::future , await, std::future .
, resumable - , await future . , , await. , await. , , .
resumable , " ?". - . , . resumable . Thomas Heller ( ) resumable .
std::future< uint64_t> fibonacci(uint64_t n) { if (n < 2) return std::make_ready_future(n); std::future<uint64_t> lhs_future = std::async(&fibonacci, n-1); //.unwrap(); std::future<uint64_t> rhs_future = fibonacci(n-2); return dataflow( unwrapped([](uint64_t lhs, uint64_t rhs) { return lhs + rhs; }) , lhs_future, rhs_future ); }
. , "dataflow" await . future, . ++11 ++14 - .
- resumable ?
, , . Hartmut Kaiser , resumable . , \ . , .
resumable
- ( ) resumable . - , , . async/await, (if/else, for ..). . N3650 , std::future:
future<int> f(shared_ptr str) { shared_ptr<vector> buf = ...; return str->read(512, buf) .then([](future<int> op)// lambda 1 { return op.get() + 11; }); } future<void> g() { shared_ptr s = ...; return f(s).then([s](future<int> op) // lambda 2 { s->close(); }); }
resumable :
future<void> f(stream str) async { shared_ptr<vector> buf = ...; int count = await str.read(512, buf); return count + 11; } future g() async { stream s = ...; int pls11 = await f(s); s.close(); }
resumable (, , ). . , Herb Sutter BUILD:
std::string read( std::string file, std::string suffix ) { std::istream fi = open(file).get(); std::string ret, chunk; while( (chunk = fi.read().get()).size() ) ret += chunk + suffix; return ret; }
" " - future::get() std::future. , get() then(). , .
task<std::string> read( std::string file, std::string suffix ) { return open(file) .then([=](std::istream fi) { auto ret = std::make_shared<std::string>(); auto next = std::make_shared<std::function<task()>>( [=]{ fi.read() .then([=](std::string chunk) { if( chunk.size() ) { *ret += chunk + suffix; return (*next)(); } return *ret; }); }); return (*next)(); }); }
.then() . async/await:
task<std::string> read( std::string file, std::string suffix ) __async { std::istream fi = __await open(file); std::string ret, chunk; while( (chunk = __await fi.read()).size() ) ret += chunk + suffix; return ret; }
task<std::string>
, . await , .then(). __async __await , Visual Studio.
. , - . std::future, auto .then , - , . resumable . , , , async/await. resumable , "" , std::future, 1:0 resumable .
. , resumable . , ++? . . . - 2 : . - ? . , . . ? ? futures (- ). , , , . resumable (, ) " ": , , , - " ".
, resumable . std::(shared_)future void. , boost::future hpx::future. , "", . - resumable VArgs, -. , variadic templates. , , resumable , , std::future - copy/move .
, ++14. -, ( ?) ++14 ( ) - . - ++11 . , - ++y1. resumable - (TS), - WG21. , resumable , . , . , CTP Visual Studio ( . : !). __async __await.
, . ++14 .then() future, await std::future::get.
. - , - . resumable . , Cilk ( - ). - resumable - - , .
( __async\__await ?). resumable STL Boost - .
, resumable - - (. ). , , . -, ? , , , - .
, , resumable . - resumable lambda functions ? - WG21, 2013 .
- N3722
resumable . , async resumable. , resumable "resumable", - . await .
, std::future . , s, :
get(), then(), callable object s, s& const s. get().
is_ready(), future
, s::promise_type, resumable . set_value(T) set_exception(exception_ptr). s::promise_type s.
, " " "". STL , , , - . - sequence , , , ( ).
yield:
sequence<int> range(int low, int high) resumable { for(int i = low; i <= high; ++i) { yield i; } }
yield i sequence. sequence , yield. - , , . yield await .
Source: https://habr.com/ru/post/203724/
All Articles