アプリケーションでスレッド化と同期にブースト ライブラリを使用しています。
まず第一に、同期時のスレッド内での例外は、私にとってコンパイルの新しいことだと言わなければなりません。いずれにせよ、以下は私が達成したい疑似コードです。通知を行っているスレッドからスローされた可能性があるのと同じ例外をスローする同期スレッドが必要です。どうすればこれを達成できますか?
ブースト スレッド モデルを使用したクロス スレッド インタラクションによる例外のスローに関するスタック オーバーフローのトピックが見つかりませんでした
よろしくお願いします!
// mutex and scondition variable for the problem
mutable boost::mutex conditionMutex;
mutable boost::condition_variable condition;
inline void doTheThing() const {
if (noone doing the thing) {
try {
doIt()
// I succeeded
failed = false;
condition.notify_all();
}
catch (...) {
// I failed to do it
failed = true;
condition.notify_all();
throw
}
else {
boost::mutex::scoped_lock lock(conditionMutex);
condition.wait(lock);
if (failed) {
// throw the same exception that was thrown from
// thread doing notify_all
}
}
}