@@ -368,7 +368,7 @@ void ParallelEventDispatcher::do_parallel_dispatcher_loops(
368
368
calin::io::data_source::DataSourceFactory<
369
369
calin::ix::iact_data::telescope_event::TelescopeEvent>* src_factory,
370
370
unsigned nthread, unsigned log_frequency,
371
- std::chrono::system_clock::time_point& start_time,
371
+ std::chrono::system_clock::time_point& start_time,
372
372
std::atomic<uint_fast64_t >& ndispatched)
373
373
{
374
374
std::vector<ParallelEventDispatcher*> sub_dispatchers;
@@ -423,6 +423,8 @@ void ParallelEventDispatcher::do_parallel_dispatcher_loops(
423
423
}
424
424
425
425
for (auto & i : threads)i.join ();
426
+ threads.clear ();
427
+ threads_active = 0 ;
426
428
427
429
if (exceptions_raised) {
428
430
for (auto * d : sub_dispatchers) {
@@ -437,7 +439,33 @@ void ParallelEventDispatcher::do_parallel_dispatcher_loops(
437
439
438
440
for (auto * d : sub_dispatchers)
439
441
{
440
- d->dispatch_leave_run ();
442
+ ++threads_active;
443
+ threads.emplace_back ([d,&threads_active,&exceptions_raised](){
444
+ try {
445
+ d->dispatch_leave_run ();
446
+ } catch (const std::exception & x) {
447
+ util::log::LOG (util::log ::FATAL) << x.what ();
448
+ ++exceptions_raised;
449
+ --threads_active;
450
+ return ;
451
+ }
452
+ --threads_active;
453
+ });
454
+ }
455
+
456
+ for (auto & i : threads)i.join ();
457
+ threads.clear ();
458
+ threads_active = 0 ;
459
+
460
+ if (exceptions_raised) {
461
+ for (auto * d : sub_dispatchers) {
462
+ delete d;
463
+ }
464
+ throw std::runtime_error (" Exception(s) thrown in threaded merge processing" );
465
+ }
466
+
467
+ for (auto * d : sub_dispatchers)
468
+ {
441
469
d->dispatch_merge_results ();
442
470
delete d;
443
471
}
0 commit comments