Commit aeb61e47 authored by Martin Reinecke's avatar Martin Reinecke

Merge branch 'parallel-exceptions' into 'master'

Handle exceptions thrown in parallel regions

See merge request !24
parents 98bcb4c3 e551513b
......@@ -742,17 +742,26 @@ void thread_map(size_t nthreads, Func f)
auto & pool = get_pool();
latch counter(nthreads);
exception_ptr ex;
mutex ex_mut;
for (size_t i=0; i<nthreads; ++i)
{
pool.submit(
[&f, &counter, i, nthreads] {
[&f, &counter, &ex, &ex_mut, i, nthreads] {
thread_id = i;
num_threads = nthreads;
f();
try { f(); }
catch (...)
{
lock_guard<mutex> lock(ex_mut);
ex = current_exception();
}
counter.count_down();
});
}
counter.wait();
if (ex)
rethrow_exception(ex);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment