Repository navigation
Apply correct TBB shutdown mechanism - #16008
Merged
Merged
Conversation
Please consider the following formatting changes to AliceO2Group#16008
sawenzel
requested changes
Oct 26, 2026
sawenzel
left a comment
Collaborator
There was a problem hiding this comment.
Thanks. This is an important improvement and can go in after small considerations discussed in-line.
| Bool_t generateEvent() override; | ||
| Bool_t importParticles() override; | ||
| void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override; | ||
| void stop() override; // end-of-stream hook that closes the TBB task arena |
Collaborator
There was a problem hiding this comment.
The comment says it closes the arena, but it only joins the TBB task pool. Could you adjust it?
Suggested change
| void stop() override; // end-of-stream hook that closes the TBB task arena | |
| void stop() override; // end-of-stream hook that joins the TBB task pool |
Collaborator
Author
|
Ciao @sawenzel, I implemented your review. Let me know if something else is needed |
sawenzel
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This development fixes an issue in the shutdown of TBB in the Hybrid Generator, when end-of-stream is called, by overriding the stop() function and calling it in the generator destructor. The bug was found while analysing a Hyperloop wagon test on the PbPb_HGPYTHIA_536 MCGEN dataset. Since #15798 external generators are automatically expanded into a parallel GeneratorHybrid (8 sub-generators under IS_HYPERLOOP), and the job now fails with
[ERROR] Workflow crashed - PID 2161018 (generator-task) was killed abnormally with Segmentation fault and exited code was set to 139.At the end of the test the destructor of generator hybrid is called successfully (as demonstrated by the LOG), but ~GeneratorHybrid() only sets mStopFlag = true. mTBBTaskPoolRunner is detached and never joined, so the destructor returns at once and destroys mTaskArena, mInputTaskQueue and mResultQueue while the task pool is still using them. gens was already protected by a local copy, while the arena and the queues were not. mStopFlag is moreover only polled between tasks, so a worker inside generateEvent() keeps running until that event completes.
This is why the standard MCGEN test environment triggers it: at TTL end-of-stream is raised after a few hundred events, the generator shuts down while sub-generators are mid-event.
This fix implements the stop() override that Generator implemented since #15636 . stop() raises mStopFlag and joins mTBBTaskPoolRunner, which waits for the workers to complete. GeneratorService::stopGenerators() already calls stop() at end-of-stream in dpl_eventgen. The destructor delegates to stop() as a backstop for situation that never reach it, such as a driver sending SIGTERM and the various o2-sim executables, which do not call stopGenerators().
I tested the fix with o2-sim-dpl-eventgen on the HG-Pythia parallel configuration (end-of-stream, TTL expiry and driver SIGTERM) and with o2-sim -g hybrid in parallel, sequential, cocktail and trigger modes with various num_workers, just to make sure everything is working fine.