# Multi-thread: Random in AvalancheMC and AvalancheMicroscopic

**URL:** <https://root-forum.cern.ch/t/multi-thread-random-in-avalanchemc-and-avalanchemicroscopic/64083>\
**Category:** Garfield++\
**Created:** [August 27, 2025, 8:29am UTC](https://root-forum.cern.ch/t/multi-thread-random-in-avalanchemc-and-avalanchemicroscopic/64083 "2025-08-27T08:29:15Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![gabrielribcesario](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/gabrielribcesario/32/38927_2.png) [@gabrielribcesario](https://root-forum.cern.ch/u/gabrielribcesario)\
**Post date:** [September 3, 2025, 9:03am UTC](https://root-forum.cern.ch/t/multi-thread-random-in-avalanchemc-and-avalanchemicroscopic/64083/8 "2025-09-03T09:03:38Z")

</div>

> [@pigerard](#):
>
> Also, in my multi-threaded program, I need to end it with `app.Run()` in order to prevent the following error.

That is likely related to the behavior I’m describing [here](https://root-forum.cern.ch/t/segmentation-violation-when-plotting-with-garfield/64072/7). Basically, the PlottingEngine class sets a global plotting style with m\_style, potentially before the main function initialization since m\_style is a static member. In doing so, the ROOT environment gains ownership of the memory address pointed by m\_style. During the program shutdown, the ROOT environment frees the memory address before the unique\_ptr destructor’s is called, leading to a double-free error.

---

_[View the full topic](https://root-forum.cern.ch/t/multi-thread-random-in-avalanchemc-and-avalanchemicroscopic/64083)._
