Logo ROOT   6.12/07
Reference Guide
mt303_AsyncSimple.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_multicore
3 /// \notebook -js
4 /// Shows how to run items of work asynchronously with Async.
5 ///
6 /// \macro_code
7 ///
8 /// \author Danilo Piparo
9 /// \date August 2017
10 
11 #include "TROOT.h"
12 #include "ROOT/TFuture.hxx"
13 
14 #include <iostream>
15 
16 int workItem0()
17 {
18  printf("Running workItem0...\n");
19  return 0;
20 }
21 
22 void mt303_AsyncSimple()
23 {
24 
26 
27  auto wi0 = ROOT::Experimental::Async(workItem0);
28  auto wi1 = ROOT::Experimental::Async([]() {
29  printf("Running workItem1...\n");
30  return 1;
31  });
32 
33  printf("Running something in the \"main\" thread\n");
34 
35  std::cout << "The result of the work item 0 is " << wi0.get() << std::endl;
36  std::cout << "The result of the work item 1 is " << wi1.get() << std::endl;
37 
38  printf("All work completed.\n");
39 }
40 
41 int main()
42 {
43  mt303_AsyncSimple();
44  return 0;
45 }
TFuture< typename std::result_of< typename std::decay< Function >::type(typename std::decay< Args >::type...)>::type > Async(Function &&f, Args &&... args)
Runs a function asynchronously potentially in a new thread and returns a ROOT TFuture that will hold ...
Definition: TFuture.hxx:152
int main(int argc, char **argv)
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT&#39;s implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition: TROOT.cxx:555