Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft Consumer Channels and Central Marketing Group

Similar presentations


Presentation on theme: "Microsoft Consumer Channels and Central Marketing Group"— Presentation transcript:

1 Microsoft Consumer Channels and Central Marketing Group
3/15/2017 C++/CXの非同期処理まとめ ~VC++とC++/CXについて~ 非同期勉強会 2014/5/10 Sat Room metro大阪 遥佐保 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

2 はじめに

3 自己紹介 @hr_sao Microsoft MVP for Client Development 出没コミュニティ Room metro
3/15/2017 自己紹介 @hr_sao Microsoft MVP for Client Development 出没コミュニティ Room metro    →次回は5/20(火) C++テンプレート完全ガイド読書会    →次回は5/12(月) 次回は、5/12(月)にcpptmp読書会やるよ! 5/20(火)はめとべやエキスパート塾Uniity編やるよ © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

4 VisualC++ 特に C++/CX関連の
本日の目的 VisualC++ 特に C++/CX関連の 非同期処理関連について 理解度を深める

5 Topics C++規格 非同期処理の活用 Visual Studio 2013 VC++ Visual C++ の非同期処理
C++/CX非同期処理 まとめ

6 1. C++の規格

7 Recently Published: C++11 (2011)
3/15/2017 Recently Published: C++11 (2011) C++冬の時代を乗り越え 今まさに空前絶後の C++バージョンアップブーム © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

8 VC++2013事情 C++11/C++14/C++17(予定)
3/15/2017 VC++2013事情 C++11/C++14/C++17(予定) C++11  Rvalue references (対応完了)  ref-qualifiers  constexpr (一部)  Alignment  Inheriting constructors  Defaulted and deleted functions (対応完了)  Extended sizeof  noexcept (一部) C++11 Concurrency  Magic statics C++11 C99  __func__ (対応完了) C#のasync/awaitを意識 C#のasync/awaitを意識 C++14  auto and decltype(auto) return types  Generic lambdas (一部) C++17 (予定) Concurrency TS(?)  Resumable functions and await (一部) © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

9 2. 非同期処理の活用

10 非同期処理の活用例 1つプロセス内の処理 複数プロセス間の処理 他リソース間の処理 非同期処理 レスポンスタイムの向上
3/15/2017 非同期処理の活用例 1つプロセス内の処理 複数プロセス間の処理 他リソース間の処理 非同期処理 レスポンスタイムの向上 →「待たない」  並行処理 マルチスレッドの効率的利用 →並列処理 スループット向上 ex)ディスクアクセスの間に、CPUを利用する ex)DBからデータを取得するなど、「非同期」でよく使われる例はこれ © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

11 非同期処理の活用例 1 2 1つプロセス内の処理 複数プロセス間の処理 他リソース間の処理 非同期処理 レスポンスタイムの向上
3/15/2017 非同期処理の活用例 本日は、用語をこう定義して進めます 1 → 非同期処理 2 → 並列高速演算 1つプロセス内の処理 複数プロセス間の処理 他リソース間の処理 非同期処理 レスポンスタイムの向上 →「待たない」  並行処理 マルチスレッドの効率的利用 →並列処理 スループット向上 ex)ディスクアクセスの間に、CPUを利用する ex)DBからデータを取得するなど、「非同期」でよく使われる例はこれ 1 2 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

12 3/15/2017 3. Visual Studio 2013 VC++ © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

13 マイクロソフト社が提供するC++ライブラリ concurrency 名前空間
3/15/2017 非同期処理 C++11 std::future / std::promise / std::packaged_task / std::thread / std::async など →かなりコードが生々しい PPL Task マイクロソフト社が提供するC++ライブラリ concurrency 名前空間 いままではBoostライブラリなどで、各OSのスレッド処理を共通化したりしていた © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

14 PPL Task using concurrency → PPL : Parallel Patterns Library(MS提供)
3/15/2017 PPL Task using concurrency → PPL : Parallel Patterns Library(MS提供) VC++で用意されている非同期処理含めた 並列処理は concurrency 名前空間にまとめられて いる タスクの並列処理 (そのためにスレッドも利用) 並列アルゴリズム paralle_for_each 並列に行列演算させたり © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

15 VC++2013 1 2 プロジェクト例 種類 機能の例 非同期処理 C++ C++11 <future>
3/15/2017 VC++2013 プロジェクト例 種類 機能の例 非同期処理 C++ C++11 <future> std::thread / std::promise std::async VC++ Windows Runtime C++/CX ppltasks.h concurrency::task 並列 高速演算 DirectX (GPGPU利用) C++AMP amp.h concurrency::parallel_for_each 1 Concurrencyの中には、広くVC++で使えるものと、Windowsストアアプリだけで使えるものとある 2 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

16 C++余談 Lambda grammer

17 Classic C #include <stdio.h> int main() {
printf( “Hello World\n” ); return 0; }

18 C++03 #include <iostream> int main() {
std::cout << “Hello World.” << std::endl; return 0; }

19 C++11 lambdas 最小定義 [ ]{ }; [ ]( ){ }; int main() {
3/15/2017 C++11 lambdas 最小定義 [ ]{ }; [ ]( ){ }; int main() { [ ]( ){ }( ); // 空のラムダ式 return 0; } © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

20 3/15/2017 C++11 (1) int main() { [ ]{ std::cout << “Hello World!” << std::endl; }( ); return 0; } {}の中が関数 ()で関数呼び出し © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

21 C++11 (2) int main() { auto f = [ ]{
3/15/2017 C++11 (2) int main() { auto f = [ ]{ std::cout << “Hello World!” << std::endl; }; f( ); // 代入されたラムダを関数呼び出し return 0; } ラムダはオブジェクト © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

22 C++11 (3) int main() { [ ]( std::string const &str ) // 引数
3/15/2017 C++11 (3) int main() { [ ]( std::string const &str ) // 引数 { std::cout << str << std::endl; } // コード ( “Hello World!” ); // 呼び出し return 0; } Hello World文字を引数にしている © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

23 C++14 generic lambda int main() { auto plus = [ ]( auto x, auto y ) {
3/15/2017 C++14 generic lambda int main() { auto plus = [ ]( auto x, auto y ) { return x + y; }; plus( 5, 5 ); plus( std::string( "Hello “ ), std::string( "World“ )); return 0; } これを踏まえたうえで次 ちなみに以下generic lamdbaの例 <C++14> auto glambda = [ ] ( auto a ) { return a; }; <C++11> struct unnamed_lambda { template<typename T> auto operator( )(T a) const { return a; } auto lambda = unnamed_lambda(); © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

24 3/15/2017 4. Visual C++非同期処理 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

25 VC++非同期処理(1) まずは ppltasks.h の concurrency::task を使ってみる

26 concurrency::task sample
3/15/2017 concurrency::task sample #include "stdafx.h“ #include <iostream> #include <ppltasks.h> // <future>でもOK int main( ){ int num = 0; concurency::task<int>t01([ &num ](){ // taskで別タスク実行 ++ num; return( num ); // 非同期処理で返すものを設定 }); int result = t01.get(); // 同期を取る return( 0 ); } std::asyncと同じ形 結局、concurrency::taskを使っても、この程度だと std::async と全く同じ © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

27 .then()を用いたTask のつなげ方 (1)
concurency::task<int> t1([]() { return( 1 ); }); concurency::task<int> t2 = t1.then([](int n) { return( ++n ); }); concurency::task<int> t3 = t2.then([](int n) { return( ++n ); }); int result = t3.get(); // 同期 型は合わせること .then で返り値を 別のタスクに渡す どんどんつなげることが可能

28 .then()を用いたTask のつなげ方 (2)
3/15/2017 .then()を用いたTask のつなげ方 (2) concurency::task<int> t([](){ return( 1 ); }).then([](int n){ return( ++n ); }) この例だと、途中で例外が起きたら、あとの .then は実行されない Task<T>にしないといけない そういえばC#でも 似たような書き方 出来ましたね © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

29 VC++非同期処理(2) pplawait.h の resumable / await を使ってみる

30 Visual C++ Compiler November 2013 CTP
3/15/2017 VC++非同期処理 resumable / await C#の async/await の C++版 Visual C++ Compiler November 2013 CTP © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

31 VC++コンパイラを選択

32 resumable/await Sample
3/15/2017 resumable/await Sample #include <future> #include <pplawait.h> concurrency::task<void> my_proc(void) __resumable{ auto x = []() __resumable -> concurrency::task<void> { std::cout << “abc." << std::endl; }; __await x(); std::cout << “def." << std::endl; } int main() { auto task = my_proc(); task.wait(); __await の後ろはスタックコールバックと思ったらいい .then を書く必要がない © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

33 3/15/2017 5. C++/CX非同期処理 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

34 C++/CX事情 C++11 前提のコーディング 自作スレッドは使わない(PPL Task標準利用)
3/15/2017 C++/CX事情 C++11 前提のコーディング 自作スレッドは使わない(PPL Task標準利用) std::shared_ptr, ラムダ式など積極的に利用 C++の規格のバージョンアップに伴ってコー ディング方法もここ数年変化 これらの合わせ技 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

35 C++/CX Sample .then版 void App1::MainPage::my_btn_click(
3/15/2017 C++/CX Sample .then版 void App1::MainPage::my_btn_click( Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { task<StorageFile^>( KnownFolders::DocumentsLibrary->CreateFileAsync( my_txt->Text ,CreationCollisionOption::ReplaceExisting) ).then([this](StorageFile^ file) my_btn_01->Content = "ファイル作成しました"; }); } Windowsストアアプリでファイル操作を逆に同期にすることは出来ない(難しい) © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

36 C++/CX Sample resumable/await版
3/15/2017 C++/CX Sample resumable/await版 concurrency::task<void> App1::MainPage::my_btn_click( Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)__resumable { auto file = __await file->CreateFileAsync( my_txt->Text, CreationCollisionOption::ReplaceExisting); my_btn_01->Content = "ファイル作成しました"; } .thenよりもちょっとは見やすくなった…? © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

37 VC++からC++/CXそして WindowsRuntimeでの活用
App container ( package manifest ) UI controls ( XAML ) 相互互換のための C++言語拡張機能 (中間の変換無し) C++実装Class (ネイティブ) VSプロジェクト テンプレート C++/CX

38 非同期構成/操作概念 UI controls C++/CX ( XAML )
3/15/2017 非同期構成/操作概念 App container ( package manifest ) UI controls ( XAML ) C++/CX C++実装クラス (ネイティブ) concurrency::create_async Windows::Foundation::IAsyncActionなど concurrency::task 他のWindows Runtimeと 非同期通信 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

39 VC++のPPLで用意している 並列化の手法(C++ネイティブ)
3/15/2017 VC++のPPLで用意している 並列化の手法(C++ネイティブ) 処理 利用クラス/アルゴリズム/メソッド 非同期タスク処理 concurrency::task 並列に分割した処理の グルーピング concurrency::task_group concurrency::structured_task_group タスク処理の継続 concurrency::task::then concurrency::task はテンプレートクラス © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

40 WindowsRuntimeで用意しているTask
3/15/2017 WindowsRuntimeで用意しているTask 4つの非同期インターフェース Windows::Foundation 他の言語ともやり取りできる 非同期アクション IAsyncAction 非同期進行状況 IAsyncActionWithProgress<TProgress> 結果を返す非同期 IAsyncOperation<TResult> 結果も返すし進行も判る IAsyncOperationWithProgress<TResult, TProgress> やっとC#にも通じる話が出てきた © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

41 C++/CXで用意している 他言語互換用のTask
処理 利用クラス 非同期タスク処理 concurrency::create_async 他言語やり取りする場合は、create_async →4つの非同期インタフェースのどれかでラップ C++クラスの世界で完結する場合は taskでOK

42 (余談)C++/CXで用意している Windows Runtimeのスレッド
3/15/2017 (余談)C++/CXで用意している Windows Runtimeのスレッド スライド非表示ページ Platform::Agile<T> Windows Runtimeのクラスのインスタンス →どのスレッドからでもアクセス可能 普通はクライアント側で Platform::Agile<T> を利用する必要なし XAMLなどのUIスレッドはAgileは継承していない(マルチスレッ ドに出来ない) 一部を除いて © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

43 Windows Store Apps demo

44 XAMLからのクリックイベント(1) <Button x:Name="SortButton" Content="Sort" Click="SortButton_Click"/>

45 別のスレッドプールを指定することも出来る
XAMLからのクリックイベント(2) void ScenarioInput1::SortButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e){ SortButton->IsEnabled = false; textblock->Text = "ソート中(*´Д`)..."; sortVector = ExtractInts( Textbox->Text ); create_task([this] { MergeSort( sortVector.begin(), sortVector.end() ); }).then( [this] { textblock->Text = MakeString( sortVector ); SortButton->IsEnabled = true; }, task_continuation_context::use_current()); } この場合の.thenは、 UIスレッドに返している 別のスレッドプールを指定することも出来る

46 (余談)Visual C++並列高速化演算
3/15/2017 (余談)Visual C++並列高速化演算 © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

47 とりあえず動かす時には、 デバックなし実行[Ctrl+F5]
3/15/2017 C++AMP C++言語の拡張 現在のWindowsが動くOS環境であれば、問題なく 動作する模様  →Intel/AMD/NVIDIAなどのGPUでOK concurrency::parallel_for_each など とりあえず動かす時には、 デバックなし実行[Ctrl+F5] © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

48 3/15/2017 6. まとめ © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

49 Summry C++11標準のタスク処理 +マイクロソフト提供のPPL タスク処理 がある!
3/15/2017 Summry C++11標準のタスク処理 +マイクロソフト提供のPPL タスク処理 がある! resumable/await は C#の async/await VC++ならconcurrency::task が便利 C++/CXならconcurrency::create_async がよし なにやってくれる これだけは覚えて帰ってね! © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

50 参考 Hilo での非同期プログラミング パターンとヒント (C++ と XAML を使っ た Windows ストア アプリ) C++ における Windows ストア アプリ用の非同期操作の作成 C++AMPを用いたGPUプログラミング x.html Windows 8 Asynchronous Operations in C++ with PPL a0d


Download ppt "Microsoft Consumer Channels and Central Marketing Group"

Similar presentations


Ads by Google