C++でthreadを使用している際に、Thread内部でエラーが発生すると動作が停止してしまいます。
cpp
1#include <thread> 2#include <iostream> 3 4void th (int n) { 5 try { 6 for () { 7 /*処理*/ 8 /*これだと例外発生後にthreadが停止する??*/ 9 } 10 } 11 catch (AException &a) { 12 /*エラー時の処理*/ 13 } 14 catch (BException &b) { 15 /*エラー時の処理*/ 16 } 17 catch (CException &c) { 18 /*エラー時の処理*/ 19 } 20 catch (std::exception &e) { 21 /*エラー時の処理*/ 22 } 23 catch (...) { 24 /*エラー時の処理*/ 25 } 26} 27 28int main () { 29 try { 30 std::thread thread1(th, 1); 31 std::thread thread2(th, 2); 32 std::thread thread3(th, 3); 33 thread1.join(); 34 thread2.join(); 35 thread3.join(); 36 } 37 catch (std::exception &e) { 38 /*エラー時の処理*/ 39 } 40 catch (...) { 41 /*エラー時の処理*/ 42 } 43} 44 45
AExceptionを意図的に発生させた際に、発生させたスレッドが停止してしまいます
どうすれば停止せずに続けられますか?
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/13 11:13