# Multithreading ROOT project

**URL:** <https://root-forum.cern.ch/t/multithreading-root-project/37010>\
**Category:** Newbie\
**Created:** [November 29, 2019, 5:15pm UTC](https://root-forum.cern.ch/t/multithreading-root-project/37010 "2019-11-29T17:15:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fresh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/2acd7d/32.png) [@fresh](https://root-forum.cern.ch/u/fresh)\
**Post date:** [November 29, 2019, 5:15pm UTC](https://root-forum.cern.ch/t/multithreading-root-project/37010/1 "2019-11-29T17:15:01Z")

</div>

Hi, I’m new to this forum so I didn’t know where to post this.  
I’m working on a C++ binary which creates and fills multiple TH1F histograms with a huge amount of entries. To speed things up, I decided to try multithreading the program using the TThreadedObject class and wrapping my histograms in it.  
I just can’t work out whether my project needs the following two lines:  
`ROOT::EnableImplicitMT(NTasks); ROOT::EnableThreadSafety();`  
Here `NTasks` is the number of threads I want to launch.

Also, is it a good idea to use TThreadedObject? Or is it better to use plain standard library threads and mutexes?

---

<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:** [November 29, 2019, 6:02pm UTC](https://root-forum.cern.ch/t/multithreading-root-project/37010/2 "2019-11-29T18:02:23Z")

</div>

Hi @fresh,  
welcome to the ROOT forum!

`ROOT::EnableImplicitMT` is required to work with ROOT objects in a multi-thread application. It implies `ROOT::EnableThreadSafety`, as per [the docs](https://root.cern/doc/master/namespaceROOT.html#a06f2b8b216b615e5abbc872c9feff40f).

If what you would do is to fill a different TH1F per thread and then merge them at the end, `TThreadedObject` is a good idea – that’s exactly what it’s for, and you don’t have to worry about the gory details.

Cheers,  
Enrico
