19 const UInt_t poolSize = 4U;
21 Int_t mt201_parallelHistoFill()
23 ROOT::EnableThreadSafety();
27 ROOT::TThreadedObject<TH1F> ts_h(
"myHist",
"Filled in parallel", 128, -8, 8);
30 auto fillRandomHisto = [&](
int seed = 0) {
38 auto histogram = ts_h.Get();
39 for (
auto i : ROOT::TSeqI(1000000)) {
40 histogram->Fill(rndm.Gaus(0, 1));
45 auto seeds = ROOT::TSeqI(1, poolSize + 1);
47 std::vector<std::thread> pool;
53 auto monitor = [&]() {
54 for (
auto i : ROOT::TSeqI(5)) {
55 std::this_thread::sleep_for(std::chrono::duration<double, std::nano>(500));
56 auto h = ts_h.SnapshotMerge();
57 std::cout <<
"Entries for the snapshot " << h->GetEntries() << std::endl;
60 pool.emplace_back(monitor);
63 for (
auto seed : ROOT::TSeqI(seeds)) {
64 pool.emplace_back(fillRandomHisto, seed);
72 auto sumRandomHisto = ts_h.Merge();
74 std::cout <<
"Entries for the total sum " << sumRandomHisto->GetEntries() << std::endl;
76 auto c =
new TCanvas();
77 sumRandomHisto->DrawClone();