再開可能機能

先週、C ++の世界で興味深いイベントが起こりました。 Microsoftは、Visual Studio 2013のC ++コンパイラの更新プログラムのリリースを発表しました。それ自体、Visual Studioまたはそのサービスパックとは別にコンパイラを更新することは、すでにMicrosoftにとって重要なイベントです。 しかし、さらに興味深いのは、この更新に含まれるものです。 完全なリストは上記のリンクで見つけることができ、私は1つのポイントにのみ焦点を当てます-再開可能な機能 状況を完全に理解するために:マイクロソフトは、C ++標準化委員会とgcc \ clang開発者の両方を十分にレビューし、将来の実験的および未承認の機能に基づいて、将来のC ++ 17標準の実験的および未承認の機能の実装をリリースしました(ここでは慎重に必要です) C ++ 14標準。これは、日常のプログラミングにはまだ含まれていないC ++ 11機能の修正です。



オタクの動きは十分だと思いませんか?



そして、以下はmeetingcpp.comの記事の翻訳であり、この機能とその使用方法について説明しています。





最近のBUILDカンファレンスで、Herb SutterはC ++の将来について話しました。 彼の講演は、C ++ 11およびC ++ 14の美しい例でいっぱいでした。 そして突然、どこからともなく-再開可能な機能。 ハーブはstd :: futureおよびresumable functionsを説明しているドキュメントの著者の1人であるため、彼らの言及は私にとって驚きではありませんでしたが、私が驚いたのは、このトピックにどれだけ注意を払ったか、resumableという事実の言及でした関数はVisual Studio 2013の更新に含まれます(VS2013のリリースに含まれていなくても、IDEの次のバージョンよりもずっと前です)。



私は小さなネタバレから始めます:これは少なくともC ++ 1yの機能であり、C ++ 14には含まれませんが、非同期および並列プログラミングは将来の言語開発のトレンドになるため、再開可能な関数は新しい標準の有機的な部分になります。 将来的には、この機能はすべてのコンパイラでサポートされ、現時点では、Microsoftは独自の実装で他の機能よりも一歩進んでいます。 この機能がC#からの非同期/待機と類似していることは秘密ではありません。



再開可能な関数とは何ですか?


これは、実際、私たちが見つけようとしている主な質問です。 これが何であるか、 N3650文書がそれらをどのように定義するかを説明する前に、再開可能な関数はstd :: futureが.then()メソッドで展開されるという仮定に基づいているため、少し休憩して先物について説明する必要がありますドキュメントN3634で提案されているとおり 。 futureは非同期操作の結果です。 これは、非同期プログラミングの基本概念の1つです。 futureは、非同期タスクのステータスとその結果に関する情報が格納されている場所です(既に利用可能な場合)。 get()メソッドを呼び出して、非同期操作が完了するのを待って結果を返す(これは既に標準で実装されています)か、.then()メソッドを介してそのハンドラーを登録します(まだ標準ではありません)。 C ++ 11に.then()が存在しないことは最も批判されているエラーの1つであり、C ++ 14ではstd :: futureに対するその他の改善とともに修正されるでしょう。



C ++ 11ではC ++にラムダが追加されたため、これを組み合わせることで、ラムダ関数(コールバック)への非同期呼び出しのチェーンを構築できます。 これで、非同期タスクの実行を開始し、.then()メソッドを介して登録されたハンドラーでその完了に応答できるようになります。 「サーバーの応答を読み取り、解析し、処理します...」 途中でエラーチェックとログ記録を行います。 このアプローチは一部の言語では一般的ですが、C ++ではまだ一般的ではありません。 このような強力なメカニズムをよく理解すると、将来のコードの記述方法に深刻な影響を与える可能性があります。



std :: futureを示す短い例:



std::future<int> f_int = make_dummy_future(42); int i = f_int.get() //     f_int.then([](std::future<int> i){/* deal with it */}) //  
      
      







再開可能な関数の考え方は、互いに接続された先物のチェーンをコンパイラが処理し、.then()を介してそれらを正しく呼び出すようにすることです。

これを実現するには、asyncとawaitという2つの新しいキーワードを宣言することをお勧めします。 これはstd :: asyncライブラリとは関係ないことに注意してください。これはライブラリではなく、プログラミング言語の拡張です。 関数は、宣言後、ただし生成された例外の指定前に、asyncキーワードでマークされます。



 void resumable_function(int i) async
      
      







そのため、コンパイラはこれが再開可能な関数であることを認識します。 そして、楽しみが始まります。 これは機能ですが、まだ機能がかなり制限されています。 これらの最初は戻り値の型です-voidまたはstd :: future / std :: shared_futureのいずれかです。 おそらくstd::( shared_)futureに変換できる型も許可されますが、一般的に暗黙的な変換はここでは最良の解決策ではないため、委員会は厳密な型の一致を選択することを決定します。 現在のドキュメントでは、Tを返すことが許可されており、暗黙的にTに変換されます
 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 .


































All Articles