# Filling separate ttrees in parallel threads

**URL:** <https://root-forum.cern.ch/t/filling-separate-ttrees-in-parallel-threads/27175>\
**Category:** ROOT\
**Tags:** tree\
**Created:** [December 4, 2017, 2:21pm UTC](https://root-forum.cern.ch/t/filling-separate-ttrees-in-parallel-threads/27175 "2017-12-04T14:21:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhrdinka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/c6cbf5/32.png) [@jhrdinka](https://root-forum.cern.ch/u/jhrdinka)\
**Post date:** [December 4, 2017, 2:21pm UTC](https://root-forum.cern.ch/t/filling-separate-ttrees-in-parallel-threads/27175/1 "2017-12-04T14:21:04Z")

</div>

I have two separate writers which run in parallel. Each writer has its own ttree (with different branches) and fills it (with independent objects) during the execution, which happens in parallel.  
When executing my program with two threads I get a reproducible race condition. The segmentation fault happens when both independent writers call the fill()-method of their ttree in different threads.  
Do you know what could be the problem and how I could solve it?

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [December 4, 2017, 2:49pm UTC](https://root-forum.cern.ch/t/filling-separate-ttrees-in-parallel-threads/27175/2 "2017-12-04T14:49:17Z")

</div>

Hi,  
do you call `ROOT::EnableThreadSafety()` at the beginning of your application?

---

<div class="post-metadata">

**Author:** ![jhrdinka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/c6cbf5/32.png) [@jhrdinka](https://root-forum.cern.ch/u/jhrdinka)\
**Post date:** [December 4, 2017, 3:13pm UTC](https://root-forum.cern.ch/t/filling-separate-ttrees-in-parallel-threads/27175/3 "2017-12-04T15:13:47Z")

</div>

> [@eguiraud](#):
>
> ROOT::EnableThreadSafety()

Hi,

no I did not do that. I tried it now and it works, thanks!

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [December 4, 2017, 3:16pm UTC](https://root-forum.cern.ch/t/filling-separate-ttrees-in-parallel-threads/27175/4 "2017-12-04T15:16:17Z")

</div>

We are aware multi-threading with ROOT could be documented better – working on that.  
Cheers,  
Enrico

---

<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:** [December 18, 2017, 3:16pm UTC](https://root-forum.cern.ch/t/filling-separate-ttrees-in-parallel-threads/27175/5 "2017-12-18T15:16:26Z")

</div>

Closed on December 18, 2017, 3:16pm UTC

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