# Thread safety of the ComponentAnalyticField and ComponentConstant classes

**URL:** <https://root-forum.cern.ch/t/thread-safety-of-the-componentanalyticfield-and-componentconstant-classes/63768>\
**Category:** Garfield++\
**Created:** [June 20, 2025, 12:26am UTC](https://root-forum.cern.ch/t/thread-safety-of-the-componentanalyticfield-and-componentconstant-classes/63768 "2025-06-20T00:26:15Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [June 20, 2025, 12:26am UTC](https://root-forum.cern.ch/t/thread-safety-of-the-componentanalyticfield-and-componentconstant-classes/63768/1 "2025-06-20T00:26:15Z")

</div>

Hello,

I faintly remember both `ComponentAnalyticField` and `ComponentConstant` being thread safe once, but I could be mistaken. Running a sequential job on the drift of electrons with attachment turned off yields the expect results: the electrons drift the entirety of the drift gap (from `gap` to `0[cm]`) and leave the drift medium. Meanwhile, the electrons will randomly cease their drift when running the same thing in parallel.

These are the histograms of the endpoint coordinate of some electrons, marked along the drift axis. The same behaviour can be observed for both `ComponentAnalyticField` and `ComponentConstant`. Using `ComponentComsol` yields flawless results in both parallel and sequential modes.

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/1/2/121fac8ab8f7360772fbd30d94952ff9d2207a4f.png)

I’ve attached some files that will hopefully enable you to reproduce this behaviour. The file `analytic.cpp` contains the `ComponentAnalyticField` version and the file `constant.cpp` contains the `ComponentConstant` version.

[thread\_safe.zip](https://root-forum.cern.ch/uploads/short-url/xmoGHn1ZUhJPcFUMRAJahLBrcXq.zip) (18.2 KB)

Sincerely,  
Gabriel

EDIT:

> [@gabrielribcesario](#):
>
> Using `ComponentComsol` yields flawless results in both parallel and sequential modes.

I’ll have to correct myself on this statement: the same behaviour can also be observed with both `ComponentComsol` **and** `ComponentAnsys123`, it is just that for some reason they are a lot loss frequent so I did not notice the occurrences when visually inspecting the histograms at first.

I’m at home and I don’t have access to either software at the moment, so I had to improvise a slightly modified version of the Comsol and Gem examples. I had to increase the number of events and set the std output `"# failed: "` to actually be able to notice the behaviour, which could be related to the shorter drift distance that I had to use.

[thread\_safe\_field.zip](https://root-forum.cern.ch/uploads/short-url/5jmHPsHLFsnN0XTjHyU0lzSm5AW.zip) (1.5 MB)

Something strange that I’m noticing with the `ViewDrift` class in these modified examples is that I’m getting a lot less “kinks” when running in sequential mode. Seeing these new results makes me think that it is less of a component class problem and maybe something with one of the locks in `MediumMagboltz`?

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [June 20, 2025, 5:33am UTC](https://root-forum.cern.ch/t/thread-safety-of-the-componentanalyticfield-and-componentconstant-classes/63768/2 "2025-06-20T05:33:20Z")

</div>

Hi! Adding in the loop @hschindl

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [June 20, 2025, 1:59pm UTC](https://root-forum.cern.ch/t/thread-safety-of-the-componentanalyticfield-and-componentconstant-classes/63768/3 "2025-06-20T13:59:51Z")

</div>

Hi @gabrielribcesario, thanks a lot for uncovering/reporting! Very interesting… Indeed, `ComponentComsol` is a rather trivial class so my gut feeling would also be that the issue lies somewhere else… I will try to run your example and debug…

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 4, 2025, 2:00pm UTC](https://root-forum.cern.ch/t/thread-safety-of-the-componentanalyticfield-and-componentconstant-classes/63768/4 "2025-07-04T14:00:41Z")

</div>

Closed on July 4, 2025, 2:00pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
