DPDKでremote_core_launchした処理が例外を投げた時の挙動について
上記について実際に動かして調べました。
パターン1: remote_core_launchをtryに囲む
void func() /* user implementation */ { throw exception; } int main() /* developer implementation */ { dpdk_init(); try { remote_core_launch(func); } catch (e) { printf(e.what()); } }
これでは例外をキャッチできないが、一応普段どおりに terminate called after throwing an instance of ‘hogehoge’ してくれるので壊れたり(余談参照)しなかった。
余談: DPDK使ってるときに極まれにDPDKの秘孔をついてNICが使えなくなることが セキュリティキャンプであったので。(本当にDPDKの秘孔が原因か解らないけど。。)
パターン2: すべての処理の一番上からtryで囲む
void func() /* user implementation */ { throw exception; } int main() /* developer implementation */ { try { dpdk_init(); remote_core_launch(func); } catch (e) { printf(e.what()); } }
これでも例外はキャッチできない。 なおterminate called after throwing an instance of ‘hogehoge'はしてくれる
パターン3: remote_core_launchする関数をラップする
void func() /* user implementation */ { throw exception; } void wrap_func() /* developer implementation */ { try { func(); } catch (e) { printf(e.what()); } } int main() /* developer implementation */ { dpdk_init(); remote_core_launch(wrap_func); }
これで例外をしっかりキャッチできる
まとめ
STCPではパターン3を採用して実装する。 これが一番ベターな感じがするなあ。