I am using boost library for threading and synchronization in my application.
First of all I must say exceptions within threads on synchronization is compilitey new thing for me. In any case below is the pseudo code what I want to achieve. I want synchronized threads to throw same exception that MAY have been thrown from the thread doing notify. How can I achieve this?
Could not find any topics from Stack Overflow regarding exception throwing with cross thread interaction using boost threading model
Many thanks in advance!
// 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 } } }