Enviar pesquisa
Carregar
Effective Modern C++ 勉強会#8 Item38
•
1 gostou
•
1,344 visualizações
Takashi Hoshino
Seguir
Effective Modern C++ 勉強会#8 の Item 38 の紹介資料
Leia menos
Leia mais
Software
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 12
Baixar agora
Baixar para ler offline
Recomendados
Effective Modern C++ 勉強会#6 Item25
Effective Modern C++ 勉強会#6 Item25
Takashi Hoshino
10分で分かるデータストレージ
10分で分かるデータストレージ
Takashi Hoshino
トランザクションの並行実行制御 rev.2
トランザクションの並行実行制御 rev.2
Takashi Hoshino
トランザクションの並行処理制御
トランザクションの並行処理制御
Takashi Hoshino
Intel TSX 触ってみた 追加実験 (TTAS)
Intel TSX 触ってみた 追加実験 (TTAS)
Takashi Hoshino
トランザクション入門
トランザクション入門
Hiroki Kumazaki
YARN: a resource manager for analytic platform
YARN: a resource manager for analytic platform
Tsuyoshi OZAWA
メモリより大きなデータの Sufix Array 構築方法の紹介
メモリより大きなデータの Sufix Array 構築方法の紹介
Takashi Hoshino
Recomendados
Effective Modern C++ 勉強会#6 Item25
Effective Modern C++ 勉強会#6 Item25
Takashi Hoshino
10分で分かるデータストレージ
10分で分かるデータストレージ
Takashi Hoshino
トランザクションの並行実行制御 rev.2
トランザクションの並行実行制御 rev.2
Takashi Hoshino
トランザクションの並行処理制御
トランザクションの並行処理制御
Takashi Hoshino
Intel TSX 触ってみた 追加実験 (TTAS)
Intel TSX 触ってみた 追加実験 (TTAS)
Takashi Hoshino
トランザクション入門
トランザクション入門
Hiroki Kumazaki
YARN: a resource manager for analytic platform
YARN: a resource manager for analytic platform
Tsuyoshi OZAWA
メモリより大きなデータの Sufix Array 構築方法の紹介
メモリより大きなデータの Sufix Array 構築方法の紹介
Takashi Hoshino
Intel TSX HLE を触ってみた x86opti
Intel TSX HLE を触ってみた x86opti
Takashi Hoshino
Effective Modern C++ 勉強会#3 Item16
Effective Modern C++ 勉強会#3 Item16
Mitsuru Kariya
effective modern c++ chapeter36
effective modern c++ chapeter36
Tatsuki SHIMIZU
emc++ chapter32
emc++ chapter32
Tatsuki SHIMIZU
Effective modern C++ 勉強会 #3 Item 12
Effective modern C++ 勉強会 #3 Item 12
Keisuke Fukuda
Effective modern-c++#9
Effective modern-c++#9
Tatsuki SHIMIZU
Effective Modern C++ 勉強会 Item 22
Effective Modern C++ 勉強会 Item 22
Keisuke Fukuda
Effective Modern C++ 勉強会#3 Item 15
Effective Modern C++ 勉強会#3 Item 15
Mitsuru Kariya
Effective Modern C++ study group Item39
Effective Modern C++ study group Item39
Takatoshi Kondo
Effective Modern C++ 勉強会#7 Item 27
Effective Modern C++ 勉強会#7 Item 27
Mitsuru Kariya
Effective Modern C++ 勉強会 Item26
Effective Modern C++ 勉強会 Item26
Akihiro Nishimura
Effective Modern C++勉強会#2 Item 11(,12)
Effective Modern C++勉強会#2 Item 11(,12)
Keisuke Fukuda
10分で分かるバックアップとレプリケーション
10分で分かるバックアップとレプリケーション
Takashi Hoshino
Effective modern c++ 8
Effective modern c++ 8
uchan_nos
Effective Modern C++ Item 24: Distinguish universal references from rvalue re...
Effective Modern C++ Item 24: Distinguish universal references from rvalue re...
mooopan
Emcjp item33,34
Emcjp item33,34
MITSUNARI Shigeo
emcjp Item 42
emcjp Item 42
MITSUNARI Shigeo
Emcjp item21
Emcjp item21
MITSUNARI Shigeo
Emcpp item31
Emcpp item31
mitsutaka_takeda
Emcpp item41
Emcpp item41
mitsutaka_takeda
Serializabilityとは何か
Serializabilityとは何か
Takashi Hoshino
Isolation Level について
Isolation Level について
Takashi Hoshino
Mais conteúdo relacionado
Destaque
Intel TSX HLE を触ってみた x86opti
Intel TSX HLE を触ってみた x86opti
Takashi Hoshino
Effective Modern C++ 勉強会#3 Item16
Effective Modern C++ 勉強会#3 Item16
Mitsuru Kariya
effective modern c++ chapeter36
effective modern c++ chapeter36
Tatsuki SHIMIZU
emc++ chapter32
emc++ chapter32
Tatsuki SHIMIZU
Effective modern C++ 勉強会 #3 Item 12
Effective modern C++ 勉強会 #3 Item 12
Keisuke Fukuda
Effective modern-c++#9
Effective modern-c++#9
Tatsuki SHIMIZU
Effective Modern C++ 勉強会 Item 22
Effective Modern C++ 勉強会 Item 22
Keisuke Fukuda
Effective Modern C++ 勉強会#3 Item 15
Effective Modern C++ 勉強会#3 Item 15
Mitsuru Kariya
Effective Modern C++ study group Item39
Effective Modern C++ study group Item39
Takatoshi Kondo
Effective Modern C++ 勉強会#7 Item 27
Effective Modern C++ 勉強会#7 Item 27
Mitsuru Kariya
Effective Modern C++ 勉強会 Item26
Effective Modern C++ 勉強会 Item26
Akihiro Nishimura
Effective Modern C++勉強会#2 Item 11(,12)
Effective Modern C++勉強会#2 Item 11(,12)
Keisuke Fukuda
10分で分かるバックアップとレプリケーション
10分で分かるバックアップとレプリケーション
Takashi Hoshino
Effective modern c++ 8
Effective modern c++ 8
uchan_nos
Effective Modern C++ Item 24: Distinguish universal references from rvalue re...
Effective Modern C++ Item 24: Distinguish universal references from rvalue re...
mooopan
Emcjp item33,34
Emcjp item33,34
MITSUNARI Shigeo
emcjp Item 42
emcjp Item 42
MITSUNARI Shigeo
Emcjp item21
Emcjp item21
MITSUNARI Shigeo
Emcpp item31
Emcpp item31
mitsutaka_takeda
Emcpp item41
Emcpp item41
mitsutaka_takeda
Destaque
(20)
Intel TSX HLE を触ってみた x86opti
Intel TSX HLE を触ってみた x86opti
Effective Modern C++ 勉強会#3 Item16
Effective Modern C++ 勉強会#3 Item16
effective modern c++ chapeter36
effective modern c++ chapeter36
emc++ chapter32
emc++ chapter32
Effective modern C++ 勉強会 #3 Item 12
Effective modern C++ 勉強会 #3 Item 12
Effective modern-c++#9
Effective modern-c++#9
Effective Modern C++ 勉強会 Item 22
Effective Modern C++ 勉強会 Item 22
Effective Modern C++ 勉強会#3 Item 15
Effective Modern C++ 勉強会#3 Item 15
Effective Modern C++ study group Item39
Effective Modern C++ study group Item39
Effective Modern C++ 勉強会#7 Item 27
Effective Modern C++ 勉強会#7 Item 27
Effective Modern C++ 勉強会 Item26
Effective Modern C++ 勉強会 Item26
Effective Modern C++勉強会#2 Item 11(,12)
Effective Modern C++勉強会#2 Item 11(,12)
10分で分かるバックアップとレプリケーション
10分で分かるバックアップとレプリケーション
Effective modern c++ 8
Effective modern c++ 8
Effective Modern C++ Item 24: Distinguish universal references from rvalue re...
Effective Modern C++ Item 24: Distinguish universal references from rvalue re...
Emcjp item33,34
Emcjp item33,34
emcjp Item 42
emcjp Item 42
Emcjp item21
Emcjp item21
Emcpp item31
Emcpp item31
Emcpp item41
Emcpp item41
Mais de Takashi Hoshino
Serializabilityとは何か
Serializabilityとは何か
Takashi Hoshino
Isolation Level について
Isolation Level について
Takashi Hoshino
データベースシステムにおける直列化可能性と等価な時刻割り当てルールの提案 rev.3
データベースシステムにおける直列化可能性と等価な時刻割り当てルールの提案 rev.3
Takashi Hoshino
WalB Driver Internals
WalB Driver Internals
Takashi Hoshino
Effective Modern C++ 勉強会#1 Item3,4
Effective Modern C++ 勉強会#1 Item3,4
Takashi Hoshino
WALをバックアップとレプリケーションに使う方法
WALをバックアップとレプリケーションに使う方法
Takashi Hoshino
WalBの紹介
WalBの紹介
Takashi Hoshino
10分で分かるLinuxブロックレイヤ
10分で分かるLinuxブロックレイヤ
Takashi Hoshino
Suffix Array 構築方法の紹介
Suffix Array 構築方法の紹介
Takashi Hoshino
An Efficient Backup and Replication of Storage
An Efficient Backup and Replication of Storage
Takashi Hoshino
ログ先行書き込みを用いたストレージ差分取得の一手法
ログ先行書き込みを用いたストレージ差分取得の一手法
Takashi Hoshino
Intel TSX について x86opti
Intel TSX について x86opti
Takashi Hoshino
WalB: Block-level WAL. Concept.
WalB: Block-level WAL. Concept.
Takashi Hoshino
VMware Backup in Cybozu Labs
VMware Backup in Cybozu Labs
Takashi Hoshino
Vmbkp: VMware vSphere Incremental Backup Tool
Vmbkp: VMware vSphere Incremental Backup Tool
Takashi Hoshino
Inside database
Inside database
Takashi Hoshino
Mais de Takashi Hoshino
(16)
Serializabilityとは何か
Serializabilityとは何か
Isolation Level について
Isolation Level について
データベースシステムにおける直列化可能性と等価な時刻割り当てルールの提案 rev.3
データベースシステムにおける直列化可能性と等価な時刻割り当てルールの提案 rev.3
WalB Driver Internals
WalB Driver Internals
Effective Modern C++ 勉強会#1 Item3,4
Effective Modern C++ 勉強会#1 Item3,4
WALをバックアップとレプリケーションに使う方法
WALをバックアップとレプリケーションに使う方法
WalBの紹介
WalBの紹介
10分で分かるLinuxブロックレイヤ
10分で分かるLinuxブロックレイヤ
Suffix Array 構築方法の紹介
Suffix Array 構築方法の紹介
An Efficient Backup and Replication of Storage
An Efficient Backup and Replication of Storage
ログ先行書き込みを用いたストレージ差分取得の一手法
ログ先行書き込みを用いたストレージ差分取得の一手法
Intel TSX について x86opti
Intel TSX について x86opti
WalB: Block-level WAL. Concept.
WalB: Block-level WAL. Concept.
VMware Backup in Cybozu Labs
VMware Backup in Cybozu Labs
Vmbkp: VMware vSphere Incremental Backup Tool
Vmbkp: VMware vSphere Incremental Backup Tool
Inside database
Inside database
Effective Modern C++ 勉強会#8 Item38
1.
Effective Modern C++ 勉強会#8
Item 38 星野 喬(@starpoz) サイボウズ・ラボ 2015-08-19 1
2.
Item 38 Be aware
of varying thread handle destructor behavior. 2
3.
Thread handles • ここでは
std::thread と std::future, std::shared_future のこと • std::future と std::shared_future はこの資料で は合わせて future と呼ぶことにする 3
4.
std::thread destructor • joinable
である場合、std::terminate が呼ばれ てプロセス停止 • implicit join/detach を避けた(Item 37 参照) 4
5.
future の destructor •
時には implicit join のように振る舞う • 時には implicit detach のように振る舞う • 時には何もしないように振る舞う • 何故??? 5
6.
callee 結果の保存場所 • callee
(promise)でも caller (future) 側でもない • callee 側は先に destructor 呼ばれるケースあり • caller 側は future が移動/共有されるケースあり • future から参照され、参照カウントで管理され る shared state に結果が書かれる 6
7.
future destructor の振る舞い •
条件A: std::async 由来の shared state を参照 • 条件B: ポリシが std::launch::async • 条件C: 自分が shared state を参照する最後の future • 条件ABCを全て満たす場合、 block し、タスクの完了を待つ • それ以外の場合、 単にリソースを開放する 7
8.
何故??? • 理由1: implicit
detach は避けたかった (Item 37 参照) • 理由2: だからといって、std::thread のように std::terminate を呼んでほしくなかった (std::async は高級だから??) • だから必要があれば implicit join することにした • 色々と是非が議論された(らしい)が、C++11 から C++14 においてはそのまま 8
9.
future destructor の観察 9 int
f() { std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout << “task end” << std::endl; } int main() { { std::packaged_task<int()> pt(f); auto fut = pt.get_future(); #if 0 std::thread t(std::move(pt)); #elif 0 auto fut1 = std::async(std::launch::deferred, std::move(pt)); #elif 0 auto fut1 = std::async(std::launch::async, std::move(pt)); #endif } std::cout << “block end” << std::endl; }
10.
std::sync の返り値を受けな かった場合 • std::launch::deferred
結果を受けとる手段がないので永遠に実行 されない。 • std::launch::async その場で future が destructor が呼ばれ、 imlicit join によってタスク完了を待つ 10 eratta comments
11.
Item 38 Things
to remember • Future の destructor は通常単にメンバの destructor を呼んでメモリ開放するだけである • std::async non-deferred 呼び出し経由の shared state を持つ最後の future destructor は タスク完了を待つ (implicit join()) 11
12.
感想 • deferred std::async 関数オブジェクトで良いのでは •
non-deferred std::async promise/future 使ってくれる implicit join 機能付き std::thread、しかも std::thread は誰かがよろしく管理 してくれる • デフォルトポリシが std::launch::deferred | std::launch::async って筋悪だと思う。 • よろしくスケジュールしてくれる(わけがない) • どちらになったかで振る舞いが異なりすぎると思う 12
Baixar agora